@@ -5,14 +5,6 @@ import { darken, lighten } from './colorManipulator';
55import createPalette , { dark , light } from './createPalette' ;
66
77describe ( 'createPalette()' , ( ) => {
8- beforeEach ( ( ) => {
9- consoleErrorMock . spy ( ) ;
10- } ) ;
11-
12- afterEach ( ( ) => {
13- consoleErrorMock . reset ( ) ;
14- } ) ;
15-
168 it ( 'should create a palette with a rich color object' , ( ) => {
179 const palette = createPalette ( {
1810 primary : deepOrange ,
@@ -85,26 +77,11 @@ describe('createPalette()', () => {
8577 pink . A400 ,
8678 ) ;
8779 expect ( palette . text , 'should use dark theme text' ) . to . equal ( dark . text ) ;
88- expect ( consoleErrorMock . callCount ( ) ) . to . equal ( 0 ) ;
89- } ) ;
90-
91- it ( 'logs an error when an invalid type is specified' , ( ) => {
92- createPalette ( { type : 'foo' } ) ;
93- expect ( consoleErrorMock . callCount ( ) ) . to . equal ( 1 ) ;
94- expect ( consoleErrorMock . messages ( ) [ 0 ] ) . to . match (
95- / M a t e r i a l - U I : t h e p a l e t t e t y p e ` f o o ` i s n o t s u p p o r t e d / ,
96- ) ;
9780 } ) ;
9881
9982 describe ( 'augmentColor' , ( ) => {
10083 const palette = createPalette ( { } ) ;
10184
102- it ( 'should throw when the input is invalid' , ( ) => {
103- expect ( ( ) => {
104- palette . augmentColor ( { } ) ;
105- } ) . to . throw ( / T h e c o l o r o b j e c t n e e d s t o h a v e a / ) ;
106- } ) ;
107-
10885 it ( 'should accept a color' , ( ) => {
10986 const color1 = palette . augmentColor ( indigo ) ;
11087 expect ( color1 ) . to . deep . include ( {
@@ -135,20 +112,37 @@ describe('createPalette()', () => {
135112 } ) ;
136113 } ) ;
137114
138- describe ( 'getContrastText' , ( ) => {
139- it ( 'throws an exception with a falsy argument' , ( ) => {
140- const { getContrastText } = createPalette ( { } ) ;
115+ it ( 'should create a palette with unique object references' , ( ) => {
116+ const redPalette = createPalette ( { background : { paper : 'red' } } ) ;
117+ const bluePalette = createPalette ( { background : { paper : 'blue' } } ) ;
118+ expect ( redPalette ) . to . not . equal ( bluePalette ) ;
119+ expect ( redPalette . background ) . to . not . equal ( bluePalette . background ) ;
120+ } ) ;
121+
122+ describe ( 'warnings' , ( ) => {
123+ beforeEach ( ( ) => {
124+ consoleErrorMock . spy ( ) ;
125+ } ) ;
141126
142- [
143- [ undefined , 'missing background argument in getContrastText(undefined)' ] ,
144- [ null , 'missing background argument in getContrastText(null)' ] ,
145- [ '' , 'missing background argument in getContrastText()' ] ,
146- [ 0 , 'missing background argument in getContrastText(0)' ] ,
147- ] . forEach ( ( testEntry ) => {
148- const [ argument , errorMessage ] = testEntry ;
127+ afterEach ( ( ) => {
128+ consoleErrorMock . reset ( ) ;
129+ } ) ;
149130
150- expect ( ( ) => getContrastText ( argument ) , errorMessage ) . to . throw ( ) ;
151- } ) ;
131+ it ( 'throws an exception when an invalid type is specified' , ( ) => {
132+ createPalette ( { type : 'foo' } ) ;
133+ expect ( consoleErrorMock . callCount ( ) ) . to . equal ( 1 ) ;
134+ expect ( consoleErrorMock . messages ( ) [ 0 ] ) . to . include (
135+ 'Material-UI: the palette type `foo` is not supported' ,
136+ ) ;
137+ } ) ;
138+
139+ it ( 'throws an exception when a wrong color is provided' , ( ) => {
140+ expect ( ( ) => createPalette ( { primary : '#fff' } ) ) . to . throw (
141+ 'The color object needs to have a `main` property or a `500` property.' ,
142+ ) ;
143+ expect ( ( ) => createPalette ( { primary : { main : { foo : 'bar' } } } ) ) . to . throw (
144+ '`color.main` should be a string, but `{"foo":"bar"}` was provided instead.' ,
145+ ) ;
152146 } ) ;
153147
154148 it ( 'logs an error when the contrast ratio does not reach AA' , ( ) => {
@@ -164,11 +158,4 @@ describe('createPalette()', () => {
164158 ) ;
165159 } ) ;
166160 } ) ;
167-
168- it ( 'should create a palette with unique object references' , ( ) => {
169- const redPalette = createPalette ( { background : { paper : 'red' } } ) ;
170- const bluePalette = createPalette ( { background : { paper : 'blue' } } ) ;
171- expect ( redPalette ) . to . not . equal ( bluePalette ) ;
172- expect ( redPalette . background ) . to . not . equal ( bluePalette . background ) ;
173- } ) ;
174161} ) ;
0 commit comments