Skip to content

Instantly share code, notes, and snippets.

@avaly
Created January 12, 2017 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avaly/3ff041228a5c6f789119170c28a80367 to your computer and use it in GitHub Desktop.
Save avaly/3ff041228a5c6f789119170c28a80367 to your computer and use it in GitHub Desktop.
jest-bug-json-transform
{
"foo": 123
}
<foo>
123
</foo>
module.exports = {
process(src) {
console.log('jest-test-preprocessor', src);
return 'module.exports = ' + JSON.stringify('transformed-' + src.substr(0, 1));
}
};
const json = require('./fixture.json');
const xml = require('./fixture.xml');
describe('jest-json', function () {
it('should transform JSON', function () {
console.log('json', json);
expect(json).toEqual('transformed-{');
});
it('should transform XML', function () {
console.log('xml', xml);
expect(xml).toEqual('transformed-<');
});
});
{
"name": "jest-test",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "jest"
},
"license": "ISC",
"devDependencies": {
"jest": "^18.1.0"
},
"jest": {
"verbose": true,
"moduleFileExtensions": ["js"],
"transform": {
"\\.json$": "<rootDir>/jest-test-preprocessor.js",
"\\.xml$": "<rootDir>/jest-test-preprocessor.js"
}
}
}
@avaly
Copy link
Author

avaly commented Jan 12, 2017

$ jest --no-cache
 FAIL  ./jest.test.js
  ● jest-json › should transform JSON

    expect(received).toEqual(expected)
    
    Expected value to equal:
      "transformed-{"
    Received:
      {"foo": 123}
    
    Difference:
    
      Comparing two different types of values. Expected string but received object.
      
      at Object.<anonymous> (jest.test.js:7:18)
      at process._tickCallback (internal/process/next_tick.js:103:7)

  jest-json
    ✕ should transform JSON (10ms)
    ✓ should transform XML (1ms)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 passed, 2 total
Snapshots:   0 total
Time:        0.55s
Ran all test suites.
jest-test-preprocessor <foo>
  123
</foo>

  console.log jest.test.js:6
    json { foo: 123 }

  console.log jest.test.js:11
    xml transformed-<

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment