diff --git a/src/native/toHaveStyleRule.js b/src/native/toHaveStyleRule.js index 7fb3194..d81e46a 100644 --- a/src/native/toHaveStyleRule.js +++ b/src/native/toHaveStyleRule.js @@ -12,9 +12,9 @@ function toHaveStyleRule(component, property, expected) { * Merge all styles into one final style object and search for the desired * stylename against this object */ - const mergedStyles = styles.reduce((acc, item) => Object.assign({}, acc, item), {}); + const mergedStyles = styles.reduce((acc, item) => (Object.assign({}, acc, item)), {}); const received = mergedStyles[camelCasedProperty]; - const pass = !received && !expected && this.isNot ? false : matcherTest(received, expected); + const pass = matcherTest(received, expected, this.isNot); return { pass, diff --git a/src/toHaveStyleRule.js b/src/toHaveStyleRule.js index 929853c..ba23682 100644 --- a/src/toHaveStyleRule.js +++ b/src/toHaveStyleRule.js @@ -125,7 +125,7 @@ function toHaveStyleRule(component, property, expected, options = {}) { const declarations = getDeclarations(rules, property); const declaration = declarations.pop() || {}; const received = declaration.value; - const pass = !received && !expected && this.isNot ? false : matcherTest(received, expected); + const pass = matcherTest(received, expected, this.isNot); return { pass, diff --git a/src/utils.js b/src/utils.js index 3a09e99..2eb4874 100644 --- a/src/utils.js +++ b/src/utils.js @@ -59,7 +59,12 @@ const buildReturnMessage = (utils, pass, property, received, expected) => () => 'Received:\n' + ` ${utils.printReceived(`${property}: ${received}`)}`; -const matcherTest = (received, expected) => { +const matcherTest = (received, expected, isNot) => { + // when negating, assert on existence of the style, rather than the value + if (isNot && expected === undefined) { + return received !== undefined; + } + try { const matcher = expected instanceof RegExp ? expect.stringMatching(expected) : expected; diff --git a/test/native/toHaveStyleRule.spec.js b/test/native/toHaveStyleRule.spec.js index 4d0101e..240798f 100644 --- a/test/native/toHaveStyleRule.spec.js +++ b/test/native/toHaveStyleRule.spec.js @@ -80,6 +80,18 @@ it('negated ".not" modifier with value', () => { expect(renderer.create(