jeudi 24 mars 2016

Jest React testing es6 import/export unwanted mock

When using the ES6 import/export syntax it seems that Jest is autoMocking the components I import by default even though I explicitly turn mocking off for the component.

jest.autoMockOff();
jest.dontMock("../bundles/Opportunities/MarkAsLost.jsx");

this is the import at the top of the test component:

import MarkAsLost from "../bundles/Opportunities/MarkAsLost.jsx";

this is the export at the bottom of the component being tested:

export default MarkAsLost;

this is the result of logging the imported component in the test file:

{ [Function]
  _isMockFunction: true,
  _getMockImplementation: [Function],
  mock: { calls: [ [Object] ], instances: [ [Object] ] },
  mockClear: [Function],
  mockReturnValueOnce: [Function],
  mockReturnValue: [Function],
  mockImpl: [Function],
  mockImplementation: [Function],
  mockReturnThis: [Function],
  displayName: 'MarkAsLost' }

when I use the old style syntax i.e:

var MarkAsLost = require("../bundles/Opportunities/MarkAsLost.jsx");
module.exports = MarkAsLost;

this is the result of loggin the component which now behaves as I want in the test file

{ [Function] displayName: 'MarkAsLost' }

Any help would be appreciated

Aucun commentaire:

Enregistrer un commentaire