-
-
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.
fix(expect): do not rely on 'instanceof RegExp' (#5729)
* fix(expect): do not rely on 'instanceof RegExp' `instanceof RegExp` will not be true for RegExp objects created inside of a different NodeJS VM or Window. This commit fixes this issue by checking for 'regexp.test' function instead. * chore(CHANGELOG): entry for instanceof RegExp fix * fix(expect): silence erroneous flow errors
- Loading branch information
Showing
6 changed files
with
70 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const runJest = require('../runJest'); | ||
|
||
test('expect works correctly with RegExps created inside a VM', () => { | ||
const result = runJest('expect-in-vm'); | ||
expect(result.status).toBe(0); | ||
}); |
33 changes: 33 additions & 0 deletions
33
integration-tests/expect-in-vm/__tests__/expect-in-vm.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,33 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const vm = require('vm'); | ||
|
||
it('correctly expects RegExp inside a new VM context', () => { | ||
const fn = vm.runInNewContext( | ||
`(function(require, module, exports, __dirname, __filename, expect) { | ||
expect('ab12cd').toMatch(/ab12cd/); | ||
})`, | ||
global | ||
); | ||
|
||
const module = { | ||
exports: {}, | ||
}; | ||
|
||
fn.call( | ||
module.exports, | ||
require, | ||
module, | ||
module.exports, | ||
__dirname, | ||
__filename, | ||
expect | ||
); | ||
}); |
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,5 @@ | ||
{ | ||
"jest": { | ||
"testEnvironment": "node" | ||
} | ||
} |
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