Skip to content

Commit 692b94e

Browse files
committed
Clean up tests
1 parent e2f5b30 commit 692b94e

14 files changed

+46
-46
lines changed

test/config.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ it('throws on duplicate sections', () => {
4949
let config = '[test]\nie 10\n[production test]\nie 11'
5050
expect(() => {
5151
browserslist.parseConfig(config)
52-
}).toThrowError(/Duplicate section test in Browserslist config/)
52+
}).toThrow(/Duplicate section test in Browserslist config/)
5353
})
5454

5555
it('trims whitespaces', () => {
@@ -86,40 +86,40 @@ it('shows warning on broken package.json', () => {
8686
expect(browserslist.findConfig(BROKEN)).toEqual({
8787
defaults: ['ie 11', 'ie 10']
8888
})
89-
expect(console.warn).toBeCalled()
89+
expect(console.warn).toHaveBeenCalledTimes(1)
9090
})
9191

9292
it('shows error on key typo', () => {
9393
expect(() => {
9494
browserslist.findConfig(TYPO)
95-
}).toThrowError(/browserlist/)
95+
}).toThrow(/browserlist/)
9696
})
9797

9898
it('reads from dir wich contains both browserslist and package.json', () => {
9999
expect(() => {
100100
browserslist.findConfig(BOTH1)
101-
}).toThrowError(/contains both browserslist and package\.json/)
101+
}).toThrow(/contains both browserslist and package\.json/)
102102
})
103103

104104
it('reads from dir wich contains both .browserslistrc and package.json', () => {
105105
expect(() => {
106106
browserslist.findConfig(BOTH2)
107-
}).toThrowError(/contains both .browserslistrc and package\.json/)
107+
}).toThrow(/contains both .browserslistrc and package\.json/)
108108
})
109109

110110
it('reads from dir wich contains both .browserslistrc and browserslist', () => {
111111
expect(() => {
112112
browserslist.findConfig(BOTH3)
113-
}).toThrowError(/contains both .browserslistrc and browserslist/)
113+
}).toThrow(/contains both .browserslistrc and browserslist/)
114114
})
115115

116116
it('checks config format', () => {
117117
expect(() => {
118118
browserslist.findConfig(WRONG1)
119-
}).toThrowError(/Browserslist config should/)
119+
}).toThrow(/Browserslist config should/)
120120
expect(() => {
121121
browserslist.findConfig(WRONG2)
122-
}).toThrowError(/Browserslist config should/)
122+
}).toThrow(/Browserslist config should/)
123123
})
124124

125125
it('reads config with one string', () => {

test/country.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ it('fixes country case', () => {
4848
})
4949

5050
it('loads country from Can I Use', () => {
51-
expect(browserslist('> 1% in RU').length > 0).toBeTruthy()
51+
expect(browserslist('> 1% in RU').length > 0).toBe(true)
5252
})
5353

5454
it('loads continents from Can I Use', () => {
55-
expect(browserslist('> 1% in alt-AS').length > 0).toBeTruthy()
55+
expect(browserslist('> 1% in alt-AS').length > 0).toBe(true)
5656
})
5757

5858
it('allows omission of the space between the > and the percentage', () => {
59-
expect(browserslist('>10% in US').length > 0).toBeTruthy()
59+
expect(browserslist('>10% in US').length > 0).toBe(true)
6060
})

test/cover.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ it('throws error on no stats', () => {
5959
delete process.env.BROWSERSLIST_STATS
6060
expect(() => {
6161
browserslist('cover 70% in my stats')
62-
}).toThrowError(/statistics was not provided/)
62+
}).toThrow(/statistics was not provided/)
6363
})

test/coverage.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ it('accepts mystats to load from custom stats with dataByBrowser', () => {
6868
it('throws when no custom stats', () => {
6969
expect(() => {
7070
browserslist.coverage(['ie 8'], 'my stats')
71-
}).toThrowError(/statistics was not provided/)
71+
}).toThrow(/statistics was not provided/)
7272
})
7373

7474
it('loads country usage data from Can I Use', () => {
75-
expect(browserslist.coverage(['ie 8', 'ie 9'], 'US') > 0).toBeTruthy()
75+
expect(browserslist.coverage(['ie 8', 'ie 9'], 'US') > 0).toBe(true)
7676
})
7777

7878
it('loads continents usage data from Can I Use', () => {
79-
expect(browserslist.coverage(['ie 8', 'ie 9'], 'alt-AS') > 0).toBeTruthy()
79+
expect(browserslist.coverage(['ie 8', 'ie 9'], 'alt-AS') > 0).toBe(true)
8080
})
8181

8282
it('fixes statistics of 0 version', () => {

test/custom.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ afterEach(() => {
1414
it('throws error on invalid file', () => {
1515
expect(() => {
1616
browserslist('', { stats: 'no.json' })
17-
}).toThrowError('Can\'t read no.json')
17+
}).toThrow('Can\'t read no.json')
1818
})
1919

2020
it('takes stats file from environment variable', () => {
@@ -54,7 +54,7 @@ it('takes stats from usage data object', async () => {
5454

5555
it('works alongside global usage query', () => {
5656
let list = browserslist('> 10% in my stats, > 1%', { stats: CUSTOM_STATS })
57-
expect(list.length > 1).toBeTruthy()
57+
expect(list.length > 1).toBe(true)
5858
})
5959

6060
it('takes stats from browserslist-stats.json', () => {
@@ -70,5 +70,5 @@ it('normalizes versions', () => {
7070
it('throws error on no stats', () => {
7171
expect(() => {
7272
browserslist('> 5% in my stats')
73-
}).toThrowError(/statistics was not provided/)
73+
}).toThrow(/statistics was not provided/)
7474
})

test/direct.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ it('uses case insensitive aliases', () => {
1313
it('raises on unknown name', () => {
1414
expect(() => {
1515
browserslist('unknow 10')
16-
}).toThrowError('Unknown browser unknow')
16+
}).toThrow('Unknown browser unknow')
1717
})
1818

1919
it('raises on unknown version', () => {
2020
expect(() => {
2121
browserslist('IE 1')
22-
}).toThrowError('Unknown version 1 of IE')
22+
}).toThrow('Unknown version 1 of IE')
2323
})
2424

2525
it('uses right browser name in error', () => {
2626
expect(() => {
2727
browserslist('chrome 70, ie 11, safari 12.2, safari 12')
28-
}).toThrowError('Unknown version 12.2 of safari')
28+
}).toThrow('Unknown version 12.2 of safari')
2929
})
3030

3131
it('ignores unknown versions on request', () => {
@@ -64,6 +64,6 @@ it('supports Can I Use missing mobile versions', () => {
6464
it('missing mobile versions are not aliased by default', () => {
6565
expect(browserslist('chromeandroid 53')).not.toEqual(['and_chr 53'])
6666
expect(browserslist('and_ff 60')).not.toEqual(['and_ff 60'])
67-
expect(() => browserslist('ie_mob 9')).toThrow()
68-
expect(() => browserslist('op_mob 30')).toThrow()
67+
expect(() => browserslist('ie_mob 9')).toThrow(/Unknown version 9 of ie_mob/)
68+
expect(() => browserslist('op_mob 30')).toThrow(/Unknown version 30/)
6969
})

test/electron.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ it('supports case insensitive Electron name', () => {
1515
it('throws on unknown Electron version', () => {
1616
expect(() => {
1717
browserslist('electron 0.19')
18-
}).toThrowError(/Unknown version/)
18+
}).toThrow(/Unknown version/)
1919
})
2020

2121
it('converts Electron to Chrome in ranges', () => {
@@ -35,10 +35,10 @@ it('supports patch versions in Electron ranges', () => {
3535
it('throws on unknown Electron range version', () => {
3636
expect(() => {
3737
browserslist('electron 0.1-1.2')
38-
}).toThrowError(/Unknown version/)
38+
}).toThrow(/Unknown version/)
3939
expect(() => {
4040
browserslist('electron 0.37-999')
41-
}).toThrowError(/Unknown version/)
41+
}).toThrow(/Unknown version/)
4242
})
4343

4444
it('converts Electron versions to Chrome', () => {

test/esr.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ let browserslist = require('../')
33
it('selects Firefox ESR', () => {
44
let versions = browserslist('Firefox ESR')
55
expect(versions.length).toBeGreaterThanOrEqual(1)
6-
expect(versions.every(i => /^firefox \d+$/.test(i))).toBeTruthy()
6+
expect(versions.every(i => /^firefox \d+$/.test(i))).toBe(true)
77
})
88

99
it('uses case insensitive aliases', () => {

test/extends.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,23 @@ it('throws when external package does not resolve to an array', async () => {
8181
await mock('browserslist-config-wrong', { not: 'an array' })
8282
expect(() => {
8383
browserslist(['extends browserslist-config-wrong'])
84-
}).toThrowError(/not an array/)
84+
}).toThrow(/not an array/)
8585
})
8686

8787
it('throws when package does not have browserslist-config- prefix', () => {
8888
expect(() => {
8989
browserslist(['extends thing-without-prefix'])
90-
}).toThrowError(/needs `browserslist-config-` prefix/)
90+
}).toThrow(/needs `browserslist-config-` prefix/)
9191
})
9292

9393
it('throws when extends package has dot in path', () => {
9494
expect(() => {
9595
browserslist(['extends browserslist-config-package/../something'])
96-
}).toThrowError(/`.` not allowed/)
96+
}).toThrow(/`.` not allowed/)
9797
})
9898

9999
it('throws when extends package has node_modules in path', () => {
100100
expect(() => {
101101
browserslist(['extends browserslist-config-test/node_modules/a'])
102-
}).toThrowError(/`node_modules` not allowed/)
102+
}).toThrow(/`node_modules` not allowed/)
103103
})

test/main.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ it('trims queries', () => {
3232
})
3333

3434
it('does not accept non-string and non-array parameters', () => {
35-
expect(() => browserslist({})).toThrow()
35+
expect(() => browserslist({})).toThrow(/an array or string. Got object/)
3636
})
3737

3838
it('returns unique array', () => {
@@ -79,7 +79,7 @@ it('handles undefined stats and path correctly', () => {
7979
it('throw a error on wrong path to config', () => {
8080
expect(() => {
8181
browserslist(null, { config: IE + '2' })
82-
}).toThrowError(/Can't read/)
82+
}).toThrow(/Can't read/)
8383
})
8484

8585
if (!/^win/.test(process.platform)) {
@@ -89,7 +89,7 @@ if (!/^win/.test(process.platform)) {
8989
}
9090

9191
it('has default selection', () => {
92-
expect(browserslist.defaults.length > 0).toBeTruthy()
92+
expect(browserslist.defaults.length > 0).toBe(true)
9393
})
9494

9595
it('uses default selection on empty request and no config', () => {
@@ -111,16 +111,16 @@ it('uses default selection on disabled path', () => {
111111
it('raises on unknow query', () => {
112112
expect(() => {
113113
browserslist('good')
114-
}).toThrowError('Unknown browser query `good`')
114+
}).toThrow('Unknown browser query `good`')
115115
expect(() => {
116116
browserslist('IE === 9')
117-
}).toThrowError('Unknown browser query `IE === 9`')
117+
}).toThrow('Unknown browser query `IE === 9`')
118118
})
119119

120120
it('raises on missed version', () => {
121121
expect(() => {
122122
browserslist('IE')
123-
}).toThrowError('Specify versions in Browserslist query for browser IE')
123+
}).toThrow('Specify versions in Browserslist query for browser IE')
124124
})
125125

126126
it('sorts browsers', () => {
@@ -173,7 +173,7 @@ it('has actual browsers list in docs', () => {
173173
it('throws error on first exclude query', () => {
174174
expect(() => {
175175
browserslist(['not ie 11'])
176-
}).toThrowError('Write any browsers query (for instance, `defaults`) ' +
176+
}).toThrow('Write any browsers query (for instance, `defaults`) ' +
177177
'before `not ie 11`')
178178
})
179179

0 commit comments

Comments
 (0)