Skip to content

Commit

Permalink
Add a test.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpojer committed Apr 28, 2017
1 parent b17a65a commit 413b752
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ Object {
id=\\"foo\\"
/>
",
"snapshot serializers works with first plugin 1": "foo: 1",
"snapshot serializers works with nested serializable objects 1": "foo: bar: 2",
"snapshot serializers works with first plugin 1": "foo - 1",
"snapshot serializers works with nested serializable objects 1": "foo - bar - 2",
"snapshot serializers works with prepended plugins and default serializers 1": "
<div
aProp={
Object {
\\"a\\": 6,
}
}
bProp={foo: 8}
bProp={foo - 8}
/>
",
"snapshot serializers works with prepended plugins from expect method called once 1": "
Expand All @@ -39,6 +39,6 @@ Object {
bProp={FOO: 8}
/>
",
"snapshot serializers works with second plugin 1": "bar: 2",
"snapshot serializers works with second plugin 1": "bar - 2",
}
`;
2 changes: 1 addition & 1 deletion integration_tests/__tests__/snapshot-serializers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const snapshotsDir = path.resolve(testDir, '__tests__/__snapshots__');
const snapshotPath = path.resolve(snapshotsDir, 'snapshot-test.js.snap');

const runAndAssert = () => {
const result = runJest.json('snapshot-serializers');
const result = runJest.json('snapshot-serializers', ['--no-cache']);
const json = result.json;
expect(json.numTotalTests).toBe(7);
expect(json.numPassedTests).toBe(7);
Expand Down
3 changes: 3 additions & 0 deletions integration_tests/snapshot-serializers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"jest": {
"testEnvironment": "node",
"transform": {
"^.+\\.js$": "<rootDir>/transformer.js"
},
"snapshotSerializers": [
"./plugins/foo",
"<rootDir>/plugins/bar"
Expand Down
5 changes: 4 additions & 1 deletion integration_tests/snapshot-serializers/plugins/bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
*/
'use strict';

/* eslint-disable no-unused-vars */

const createPlugin = require('../utils').createPlugin;
module.exports = createPlugin('bar');

// We inject the call to "createPlugin('bar') through the transformer"
18 changes: 18 additions & 0 deletions integration_tests/snapshot-serializers/transformer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* 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.
*/

'use strict';

module.exports = {
process(src, filename, config, options) {
if (/bar.js$/.test(filename)) {
return `${src};\module.exports = createPlugin('bar');`;
}
return src;
},
};
2 changes: 1 addition & 1 deletion integration_tests/snapshot-serializers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

exports.createPlugin = prop => {
return {
print: (val, serialize) => `${prop}: ${serialize(val[prop])}`,
print: (val, serialize) => `${prop} - ${serialize(val[prop])}`,
test: val => val && val.hasOwnProperty(prop),
};
};

0 comments on commit 413b752

Please sign in to comment.