This repository has been archived by the owner on Mar 17, 2021. It is now read-only.
/
errors.test.js
57 lines (49 loc) · 1.87 KB
/
errors.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import loader from '../src';
describe('validation', () => {
it('errors', () => {
const validate = (options) =>
loader.call(
Object.assign(
{},
{
resourcePath: 'image.png',
query: options,
emitFile: () => {},
}
),
'a { color: red; }'
);
// The `file-loader` loader can be used as `fallback` loader and options can contain not only `file-loader` options
// so we use `additionalProperties: false` to avoid problems.
expect(() => validate({ limit: 8192 })).not.toThrow();
expect(() => validate({ name: '[path][name].[ext]' })).not.toThrow();
expect(() =>
validate({
name: () => '[hash].[ext]',
})
).not.toThrow();
expect(() => validate({ name: true })).toThrowErrorMatchingSnapshot();
expect(() => validate({ outputPath: 'assets' })).not.toThrow();
expect(() =>
validate({
outputPath: () => 'assets',
})
).not.toThrow();
expect(() => validate({ outputPath: true })).toThrowErrorMatchingSnapshot();
expect(() => validate({ publicPath: 'assets' })).not.toThrow();
expect(() =>
validate({
publicPath: () => 'assets',
})
).not.toThrow();
expect(() => validate({ publicPath: true })).toThrowErrorMatchingSnapshot();
expect(() => validate({ context: 'assets' })).not.toThrow();
expect(() => validate({ context: true })).toThrowErrorMatchingSnapshot();
expect(() => validate({ emitFile: true })).not.toThrow();
expect(() => validate({ emitFile: false })).not.toThrow();
expect(() => validate({ emitFile: 'true' })).toThrowErrorMatchingSnapshot();
expect(() => validate({ regExp: /image\.png/ })).not.toThrow();
expect(() => validate({ regExp: 'image\\.png' })).not.toThrow();
expect(() => validate({ regExp: true })).toThrowErrorMatchingSnapshot();
});
});