|
| 1 | +import jssBase from 'jss'; |
| 2 | +import jss from '../setupjss'; |
| 3 | + |
| 4 | +describe('setupjss', () => { |
| 5 | + it('should renerate prefixed class names', () => { |
| 6 | + const { classes } = jss.createStyleSheet({ |
| 7 | + root: {}, |
| 8 | + }); |
| 9 | + expect(classes.root).toMatch(/^rsg--\w+-\d+$/); |
| 10 | + }); |
| 11 | + |
| 12 | + it('jss-global plugin should be enabled', () => { |
| 13 | + const css = jss |
| 14 | + .createStyleSheet({ |
| 15 | + '@global body': { |
| 16 | + color: 'red', |
| 17 | + }, |
| 18 | + }) |
| 19 | + .toString(); |
| 20 | + expect(css).toMatch(/^body {/); |
| 21 | + }); |
| 22 | + |
| 23 | + it('jss plugins should be enabled', () => { |
| 24 | + const stylesheet = jss.createStyleSheet({ |
| 25 | + root: { |
| 26 | + backgroundColor: 'tomato', |
| 27 | + width: 1, |
| 28 | + '&:hover': { |
| 29 | + color: 'snow', |
| 30 | + }, |
| 31 | + }, |
| 32 | + child: { |
| 33 | + composes: '$root', |
| 34 | + color: 'blue', |
| 35 | + }, |
| 36 | + }); |
| 37 | + |
| 38 | + const root = stylesheet.getRule('root').style; |
| 39 | + expect(root).toEqual(expect.any(Object)); |
| 40 | + expect(root['background-color']).toBe('tomato'); |
| 41 | + expect(root.width).toBe('1px'); |
| 42 | + expect(stylesheet.classes.root).toMatch(/^rsg--root-\d+$/); |
| 43 | + |
| 44 | + const child = stylesheet.getRule('child').style; |
| 45 | + expect(child).toEqual(expect.any(Object)); |
| 46 | + expect(child.color).toBe('blue'); |
| 47 | + expect(stylesheet.classes.child).toMatch(/^rsg--child-\d+ rsg--root-\d+$/); |
| 48 | + |
| 49 | + const hover = stylesheet.rules.map['.rsg--root-2:hover']; |
| 50 | + expect(hover).toEqual(expect.any(Object)); |
| 51 | + expect(hover.style.color).toBe('snow'); |
| 52 | + }); |
| 53 | + |
| 54 | + it('base jss instance setup shoud not affect Styleguidist styles', () => { |
| 55 | + jssBase.setup(); |
| 56 | + |
| 57 | + const stylesheet = jss.createStyleSheet({ |
| 58 | + root: { |
| 59 | + width: 1, |
| 60 | + }, |
| 61 | + }); |
| 62 | + |
| 63 | + expect(stylesheet.classes.root).toMatch(/^rsg--root-\d+$/); |
| 64 | + |
| 65 | + const root = stylesheet.getRule('root').style; |
| 66 | + expect(root.width).toBe('1px'); |
| 67 | + }); |
| 68 | +}); |
0 commit comments