Skip to content

Commit

Permalink
Add more npm3 tests, quickly fix jest.addMatchers (ugh!).
Browse files Browse the repository at this point in the history
Summary:moar tests!
Closes #737

Differential Revision: D2964972

fb-gh-sync-id: 5e7649ca4ef2c51ce2695adbeef3a941615c73b3
shipit-source-id: 5e7649ca4ef2c51ce2695adbeef3a941615c73b3
  • Loading branch information
cpojer authored and facebook-github-bot-6 committed Feb 23, 2016
1 parent 7b44ca0 commit 2d10421
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/HasteModuleLoader/HasteModuleLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,9 @@ class Loader {
const runtime = {
addMatchers: matchers => {
const jasmine = this._environment.global.jasmine;
jasmine.getEnv().currentSpec.addMatchers(matchers);
const addMatchers =
jasmine.addMatchers || jasmine.getEnv().currentSpec.addMatchers;
addMatchers(matchers);
},

autoMockOff: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ describe('HasteModuleLoader', function() {
// Test twice to make sure HasteModuleLoader caching works properly
root.jest.resetModuleRegistry();
expectUnmocked(loader.requireModuleOrMock(rootPath, 'npm3-main-dep'));

// Directly requiring the transitive dependency will mock it
const transitiveDep =
loader.requireModuleOrMock(rootPath, 'npm3-transitive-dep');
expect(transitiveDep()).toEqual(undefined);
});
});

Expand All @@ -152,6 +157,30 @@ describe('HasteModuleLoader', function() {
// Test twice to make sure HasteModuleLoader caching works properly
root.jest.resetModuleRegistry();
expectUnmocked(loader.requireModuleOrMock(rootPath, 'npm3-main-dep'));

// Directly requiring the transitive dependency will mock it
const transitiveDep =
loader.requireModuleOrMock(rootPath, 'npm3-transitive-dep');
expect(transitiveDep()).toEqual(undefined);
});
});

pit('unmocks transitive dependencies in node_modules by default when using both patterns and unmock', () => {
return buildLoader({
unmockedModulePathPatterns: ['banana-module'],
}).then(loader => {
const root = loader.requireModule(rootPath, './root.js');
root.jest.unmock('npm3-main-dep');
expectUnmocked(loader.requireModuleOrMock(rootPath, 'npm3-main-dep'));

// Test twice to make sure HasteModuleLoader caching works properly
root.jest.resetModuleRegistry();
expectUnmocked(loader.requireModuleOrMock(rootPath, 'npm3-main-dep'));

// Directly requiring the transitive dependency will mock it
const transitiveDep =
loader.requireModuleOrMock(rootPath, 'npm3-transitive-dep');
expect(transitiveDep()).toEqual(undefined);
});
});
});
Expand Down

0 comments on commit 2d10421

Please sign in to comment.