diff --git a/src/index.js b/src/index.js index 39a79af..d2359ac 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,3 @@ -const toMatchStyledComponentsSnapshot = require('./matchers/toMatchStyledComponentsSnapshot') const toHaveStyleRule = require('./matchers/toHaveStyleRule') const styleSheetSerializer = require('./serializers/styleSheetSerializer') const styleSheet = require('styled-components/lib/models/StyleSheet') @@ -9,4 +8,4 @@ if (isOverV2()) { } expect.addSnapshotSerializer(styleSheetSerializer) -expect.extend({ toMatchStyledComponentsSnapshot, toHaveStyleRule }) +expect.extend({ toHaveStyleRule }) diff --git a/src/matchers/toMatchStyledComponentsSnapshot.js b/src/matchers/toMatchStyledComponentsSnapshot.js deleted file mode 100644 index 9b4aaf6..0000000 --- a/src/matchers/toMatchStyledComponentsSnapshot.js +++ /dev/null @@ -1,49 +0,0 @@ -const chalk = require('chalk') -const diff = require('jest-diff') -const stripAnsi = require('strip-ansi') -const { toMatchSnapshot } = require('jest-snapshot') - -const isAddition = line => /^\+/.test(line) - -const isDeletion = line => /^-/.test(line) - -const isClassName = line => ( - (isAddition(line) || isDeletion(line)) && - (/\.[a-zA-Z]+/.test(line) || /className="(sc-)?[a-zA-Z ]+"/.test(line)) -) - -const colorize = message => ( - message.split('\n').map((line) => { - if (isClassName(line)) { - return chalk.white(line) - } - - if (isAddition(line)) { - return chalk.red(line) - } - - if (isDeletion(line)) { - return chalk.green(line) - } - - return chalk.dim(line) - }).join('\n') -) - -function toMatchStyledComponentsSnapshot(received) { - const result = toMatchSnapshot.call(this, received) - let message - - if (!result.pass) { - message = diff(result.expected, result.actual, { - aAnnotation: 'Snapshot', - bAnnotation: 'Received', - }) - message = stripAnsi(message) - message = colorize(message) - } - - return { pass: result.pass, message } -} - -module.exports = toMatchStyledComponentsSnapshot diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index 7681f4d..235abb0 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`toMatchStyledComponentsSnapshot mount 1`] = ` +exports[`toMatchSnapshot mount 1`] = ` .c0 { padding: 4em; background: papayawhip; @@ -49,9 +49,9 @@ exports[`toMatchStyledComponentsSnapshot mount 1`] = ` `; -exports[`toMatchStyledComponentsSnapshot null 1`] = `null`; +exports[`toMatchSnapshot null 1`] = `null`; -exports[`toMatchStyledComponentsSnapshot shallow 1`] = ` +exports[`toMatchSnapshot shallow 1`] = ` .c0 { padding: 4em; background: papayawhip; @@ -66,7 +66,7 @@ exports[`toMatchStyledComponentsSnapshot shallow 1`] = ` `; -exports[`toMatchStyledComponentsSnapshot test-renderer 1`] = ` +exports[`toMatchSnapshot test-renderer 1`] = ` .c0 { padding: 4em; background: papayawhip; diff --git a/test/index.spec.js b/test/index.spec.js index 2dafcf0..e15b2d1 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -31,9 +31,9 @@ const Title = styled.h1` } ` -describe('toMatchStyledComponentsSnapshot', () => { +describe('toMatchSnapshot', () => { test('null', () => { - expect(null).toMatchStyledComponentsSnapshot() + expect(null).toMatchSnapshot() }) test('test-renderer', () => { @@ -43,7 +43,7 @@ describe('toMatchStyledComponentsSnapshot', () => { , ).toJSON() - expect(tree).toMatchStyledComponentsSnapshot() + expect(tree).toMatchSnapshot() }) test('shallow', () => { @@ -53,7 +53,7 @@ describe('toMatchStyledComponentsSnapshot', () => { , ) - expect(tree).toMatchStyledComponentsSnapshot() + expect(tree).toMatchSnapshot() }) test('mount', () => { @@ -63,7 +63,7 @@ describe('toMatchStyledComponentsSnapshot', () => { , ) - expect(tree).toMatchStyledComponentsSnapshot() + expect(tree).toMatchSnapshot() }) })