-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fcc8c2b
commit ee0e8e8
Showing
10 changed files
with
338 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/jest-matchers/src/__tests__/__snapshots__/toThrowMatchers-test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
exports[`.toThrowError() error class did not throw at all 1`] = `"Expected the function to throw an error of [36m[1m\"Err\"[22m[39m type, but it didn\'t."`; | ||
|
||
exports[`.toThrowError() error class threw, but class did not match 1`] = ` | ||
"Expected the function to throw an error of [36m[1m\"Err2\"[22m[39m type, but it didn\'t. | ||
Actual error: | ||
type: [36m[1m\"Err\"[22m[39m | ||
message: [36m[1m\"apple\"[22m[39m" | ||
`; | ||
|
||
exports[`.toThrowError() error class threw, but should not have 1`] = ` | ||
"Expected the function to not throw an error of [36m[1m\"Err\"[22m[39m type, but it did. | ||
Actual error: | ||
type: [36m[1m\"Err\"[22m[39m | ||
message: [36m[1m\"apple\"[22m[39m" | ||
`; | ||
|
||
exports[`.toThrowError() regexp did not throw at all 1`] = `"Expected the function to throw an error matching [36m[1m\"/apple/\"[22m[39m, but it didn\'t."`; | ||
|
||
exports[`.toThrowError() regexp threw, but message did not match 1`] = ` | ||
"Expected the function to throw an error matching [36m[1m\"/banana/\"[22m[39m, but it didn\'t. | ||
Actual error: | ||
type: [36m[1m\"Error\"[22m[39m | ||
message: [36m[1m\"apple\"[22m[39m" | ||
`; | ||
|
||
exports[`.toThrowError() regexp threw, but should not have 1`] = ` | ||
"Expected the function to not throw an error matching [36m[1m\"/apple/\"[22m[39m, but it did. | ||
Actual error: | ||
type: [36m[1m\"Error\"[22m[39m | ||
message: [36m[1m\"apple\"[22m[39m" | ||
`; | ||
|
||
exports[`.toThrowError() strings did not throw at all 1`] = `"Expected the function to throw an error matching [36m[1m\"apple\"[22m[39m, but it didn\'t."`; | ||
|
||
exports[`.toThrowError() strings threw, but message did not match 1`] = ` | ||
"Expected the function to throw an error matching [36m[1m\"banana\"[22m[39m, but it didn\'t. | ||
Actual error: | ||
type: [36m[1m\"Error\"[22m[39m | ||
message: [36m[1m\"apple\"[22m[39m" | ||
`; | ||
|
||
exports[`.toThrowError() strings threw, but should not have 1`] = ` | ||
"Expected the function to not throw an error matching [36m[1m\"apple\"[22m[39m, but it did. | ||
Actual error: | ||
type: [36m[1m\"Error\"[22m[39m | ||
message: [36m[1m\"apple\"[22m[39m" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
packages/jest-matchers/src/__tests__/toThrowMatchers-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @emails oncall+jsinfra | ||
*/ | ||
|
||
'use strict'; | ||
|
||
describe('.toThrowError()', () => { | ||
describe('strings', () => { | ||
it('passes', () => { | ||
expect(() => { throw new Error('apple'); }).toThrowError('apple'); | ||
expect(() => { throw new Error('banana'); }).not.toThrowError('apple'); | ||
expect(() => {}).not.toThrowError('apple'); | ||
}); | ||
|
||
test('did not throw at all', () => { | ||
let error; | ||
try { | ||
expect(() => {}).toThrowError('apple'); | ||
} catch (e) { | ||
error = e; | ||
} | ||
|
||
expect(error).toBeDefined(); | ||
expect(error.message).toMatchSnapshot(); | ||
}); | ||
|
||
test('threw, but message did not match', () => { | ||
let error; | ||
try { | ||
expect(() => { throw new Error('apple'); }).toThrowError('banana'); | ||
} catch (e) { | ||
error = e; | ||
} | ||
|
||
expect(error).toBeDefined(); | ||
expect(error.message).toMatchSnapshot(); | ||
}); | ||
|
||
test('threw, but should not have', () => { | ||
let error; | ||
try { | ||
expect(() => { throw new Error('apple'); }).not.toThrowError('apple'); | ||
} catch (e) { | ||
error = e; | ||
} | ||
|
||
expect(error).toBeDefined(); | ||
expect(error.message).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('regexp', () => { | ||
it('passes', () => { | ||
expect(() => { throw new Error('apple'); }).toThrowError(/apple/); | ||
expect(() => { throw new Error('banana'); }).not.toThrowError(/apple/); | ||
expect(() => {}).not.toThrowError(/apple/); | ||
}); | ||
|
||
test('did not throw at all', () => { | ||
let error; | ||
try { | ||
expect(() => {}).toThrowError(/apple/); | ||
} catch (e) { | ||
error = e; | ||
} | ||
|
||
expect(error).toBeDefined(); | ||
expect(error.message).toMatchSnapshot(); | ||
}); | ||
|
||
test('threw, but message did not match', () => { | ||
let error; | ||
try { | ||
expect(() => { throw new Error('apple'); }).toThrowError(/banana/); | ||
} catch (e) { | ||
error = e; | ||
} | ||
|
||
expect(error).toBeDefined(); | ||
expect(error.message).toMatchSnapshot() | ||
}); | ||
|
||
test('threw, but should not have', () => { | ||
let error; | ||
try { | ||
expect(() => { throw new Error('apple'); }).not.toThrowError(/apple/); | ||
} catch (e) { | ||
error = e; | ||
} | ||
|
||
expect(error).toBeDefined(); | ||
expect(error.message).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('error class', () => { | ||
class Err extends Error {} | ||
class Err2 extends Error {} | ||
|
||
it('passes', () => { | ||
expect(() => { throw new Err(); }).toThrowError(Err); | ||
expect(() => { throw new Err(); }).toThrowError(Error); | ||
expect(() => { throw new Err(); }).not.toThrowError(Err2); | ||
expect(() => {}).not.toThrowError(Err); | ||
}); | ||
|
||
test('did not throw at all', () => { | ||
let error; | ||
try { | ||
expect(() => {}).toThrowError(Err); | ||
} catch (e) { | ||
error = e; | ||
} | ||
|
||
expect(error).toBeDefined(); | ||
expect(error.message).toMatchSnapshot(); | ||
}); | ||
|
||
test('threw, but class did not match', () => { | ||
let error; | ||
try { | ||
expect(() => { throw new Err('apple'); }).toThrowError(Err2); | ||
} catch (e) { | ||
error = e; | ||
} | ||
|
||
expect(error).toBeDefined(); | ||
expect(error.message).toMatchSnapshot(); | ||
}); | ||
|
||
test('threw, but should not have', () => { | ||
let error; | ||
try { | ||
expect(() => { throw new Err('apple'); }).not.toThrowError(Err); | ||
} catch (e) { | ||
error = e; | ||
} | ||
|
||
expect(error).toBeDefined(); | ||
expect(error.message).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.