From 03b73b135d58d138e1982b8f3c82c9d3b8724b7d Mon Sep 17 00:00:00 2001 From: Ari Seyhun Date: Thu, 1 Aug 2019 13:16:11 +0930 Subject: [PATCH] Add test for negative custom properties --- __tests__/resolveConfig.test.js | 60 +++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/__tests__/resolveConfig.test.js b/__tests__/resolveConfig.test.js index b30151827..2ca9ff9e3 100644 --- a/__tests__/resolveConfig.test.js +++ b/__tests__/resolveConfig.test.js @@ -1130,3 +1130,63 @@ test('the original theme is not mutated', () => { }, }) }) + +test('custom properties are multiplied by -1 for negative values', () => { + const userConfig = { + theme: { + spacing: { + '1': '1px', + '2': '2px', + '3': '3px', + '4': '4px', + foo: 'var(--foo)', + bar: 'var(--bar, 500px)', + }, + margin: (theme, { negative }) => ({ + ...theme('spacing'), + ...negative(theme('spacing')), + }), + }, + } + + const defaultConfig = { + prefix: '-', + important: false, + separator: ':', + theme: {}, + variants: {}, + } + + const result = resolveConfig([userConfig, defaultConfig]) + + expect(result).toEqual({ + prefix: '-', + important: false, + separator: ':', + theme: { + spacing: { + '1': '1px', + '2': '2px', + '3': '3px', + '4': '4px', + foo: 'var(--foo)', + bar: 'var(--bar, 500px)', + }, + margin: { + '1': '1px', + '2': '2px', + '3': '3px', + '4': '4px', + foo: 'var(--foo)', + bar: 'var(--bar, 500px)', + '-1': '-1px', + '-2': '-2px', + '-3': '-3px', + '-4': '-4px', + '-foo': 'calc(var(--foo) * -1)', + '-bar': 'calc(var(--bar, 500px) * -1)', + }, + }, + variants: {}, + }) +})