mirror of https://github.com/curbengh/hexo-yam
test: utilise toThrow() to catch error
- try...catch would (incorrectly) pass the test, despite having no error
This commit is contained in:
parent
b9f4cd6173
commit
81ab472fe1
|
@ -65,20 +65,15 @@ describe('css', () => {
|
||||||
}
|
}
|
||||||
hexo.config.minify.css = customOpt
|
hexo.config.minify.css = customOpt
|
||||||
|
|
||||||
let result, expected
|
let expected
|
||||||
|
|
||||||
try {
|
|
||||||
await c(input, { path })
|
|
||||||
} catch (err) {
|
|
||||||
result = err.message
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
await new CleanCSS(customOpt).minify(input)
|
await new CleanCSS(customOpt).minify(input)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
expected = err.message
|
expected = err.message
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(result).toContain(expected)
|
expect(expected).toBeDefined()
|
||||||
|
await expect(c(input, { path })).rejects.toThrow(expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('exclude - *.min.css', async () => {
|
test('exclude - *.min.css', async () => {
|
||||||
|
|
|
@ -99,11 +99,8 @@ describe('gzip', () => {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
expected = err.message
|
expected = err.message
|
||||||
}
|
}
|
||||||
try {
|
expect(expected).toBeDefined()
|
||||||
await g()
|
await expect(g()).rejects.toThrow(expected)
|
||||||
} catch (err) {
|
|
||||||
expect(err.message).toContain(expected)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('include - exclude non-text file by default', async () => {
|
test('include - exclude non-text file by default', async () => {
|
||||||
|
|
|
@ -69,11 +69,11 @@ describe('js', () => {
|
||||||
hexo.config.minify.js = customOpt
|
hexo.config.minify.js = customOpt
|
||||||
|
|
||||||
const { error } = Terser.minify(input, customOpt)
|
const { error } = Terser.minify(input, customOpt)
|
||||||
try {
|
|
||||||
|
expect(error.message).toBeDefined()
|
||||||
|
expect(() => {
|
||||||
j(input, { path })
|
j(input, { path })
|
||||||
} catch (err) {
|
}).toThrow(error.message)
|
||||||
expect(err.message).toContain(error.message)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('exclude - *.min.js', () => {
|
test('exclude - *.min.js', () => {
|
||||||
|
|
|
@ -51,11 +51,7 @@ describe('xml', () => {
|
||||||
|
|
||||||
test('invalid input', async () => {
|
test('invalid input', async () => {
|
||||||
hexo.route.set(path, 'foo')
|
hexo.route.set(path, 'foo')
|
||||||
try {
|
await expect(jsonFn()).rejects.toThrow(/SyntaxError/)
|
||||||
await jsonFn()
|
|
||||||
} catch (err) {
|
|
||||||
expect(err.message).toContain('SyntaxError')
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('empty file', async () => {
|
test('empty file', async () => {
|
||||||
|
|
|
@ -81,11 +81,8 @@ describe('svg', () => {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
expected = err
|
expected = err
|
||||||
}
|
}
|
||||||
try {
|
expect(expected).toBeDefined()
|
||||||
await s()
|
await expect(s()).rejects.toThrow(expected)
|
||||||
} catch (err) {
|
|
||||||
expect(err.message).toContain(expected)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('include - exclude *.min.svg by default', async () => {
|
test('include - exclude *.min.svg by default', async () => {
|
||||||
|
|
Loading…
Reference in New Issue