Skip to content

Commit 1a89d91

Browse files
committed
Change mount() to shallow() in tests
1 parent 058aeb2 commit 1a89d91

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

src/Calendar.spec.jsx

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { mount, shallow } from 'enzyme';
2+
import { shallow } from 'enzyme';
33
import { getMonthStart } from '@wojtekmaj/date-utils';
44

55
import Calendar from './Calendar';
@@ -47,7 +47,7 @@ describe('Calendar', () => {
4747
});
4848

4949
it('renders YearView when given view = "year"', () => {
50-
const component = mount(
50+
const component = shallow(
5151
<Calendar view="year" />,
5252
);
5353

@@ -57,7 +57,7 @@ describe('Calendar', () => {
5757
});
5858

5959
it('renders DecadeView when given view = "decade"', () => {
60-
const component = mount(
60+
const component = shallow(
6161
<Calendar view="decade" />,
6262
);
6363

@@ -67,7 +67,7 @@ describe('Calendar', () => {
6767
});
6868

6969
it('renders CenturyView when given view = "century"', () => {
70-
const component = mount(
70+
const component = shallow(
7171
<Calendar view="century" />,
7272
);
7373

@@ -253,19 +253,20 @@ describe('Calendar', () => {
253253

254254
describe('handles drill up properly', () => {
255255
it('drills up when allowed', () => {
256-
const component = mount(
256+
const component = shallow(
257257
<Calendar view="month" />,
258258
);
259259

260260
component.instance().drillUp();
261+
component.update();
261262

262263
expect(component.state().view).toBe('year');
263264
});
264265

265266
it('calls onDrillUp on drill up', () => {
266267
const onDrillUp = jest.fn();
267268

268-
const component = mount(
269+
const component = shallow(
269270
<Calendar
270271
activeStartDate={new Date(2017, 6, 1)}
271272
onDrillUp={onDrillUp}
@@ -284,7 +285,7 @@ describe('Calendar', () => {
284285
it('refuses to drill up when already on minimum allowed detail', () => {
285286
const onDrillUp = jest.fn();
286287

287-
const component = mount(
288+
const component = shallow(
288289
<Calendar
289290
onDrillUp={onDrillUp}
290291
view="century"
@@ -299,7 +300,7 @@ describe('Calendar', () => {
299300

300301
describe('handles drill down properly', () => {
301302
it('drills down when allowed', () => {
302-
const component = mount(
303+
const component = shallow(
303304
<Calendar view="century" />,
304305
);
305306

@@ -311,7 +312,7 @@ describe('Calendar', () => {
311312
it('calls onDrillDown on drill down', () => {
312313
const onDrillDown = jest.fn();
313314

314-
const component = mount(
315+
const component = shallow(
315316
<Calendar
316317
activeStartDate={new Date(2001, 0, 1)}
317318
onDrillDown={onDrillDown}
@@ -330,7 +331,7 @@ describe('Calendar', () => {
330331
it('refuses to drill down when already on minimum allowed detail', () => {
331332
const onDrillDown = jest.fn();
332333

333-
const component = mount(
334+
const component = shallow(
334335
<Calendar
335336
onDrillDown={onDrillDown}
336337
view="month"
@@ -345,20 +346,23 @@ describe('Calendar', () => {
345346

346347
describe('handles active start date change properly', () => {
347348
it('changes active start date when allowed', () => {
348-
const component = mount(
349+
const component = shallow(
349350
<Calendar />,
350351
);
351352

352353
component.instance().setActiveStartDate(new Date(2019, 0, 1));
354+
component.update();
355+
356+
const monthView = component.find('MonthView');
353357

354-
expect(component.state().activeStartDate).toEqual(new Date(2019, 0, 1));
358+
expect(monthView.prop('activeStartDate')).toEqual(new Date(2019, 0, 1));
355359
});
356360

357361
it('calls onActiveStartDateChange on activeStartDate change', () => {
358362
const activeStartDate = new Date(2017, 0, 1);
359363
const newActiveStartDate = new Date(2018, 0, 1);
360364
const onActiveStartDateChange = jest.fn();
361-
const component = mount(
365+
const component = shallow(
362366
<Calendar
363367
activeStartDate={activeStartDate}
364368
onActiveStartDateChange={onActiveStartDateChange}
@@ -378,7 +382,7 @@ describe('Calendar', () => {
378382
describe('calls onChange properly', () => {
379383
it('calls onChange function returning the beginning of selected period by default', () => {
380384
const onChange = jest.fn();
381-
const component = mount(
385+
const component = shallow(
382386
<Calendar
383387
onChange={onChange}
384388
view="month"
@@ -392,7 +396,7 @@ describe('Calendar', () => {
392396

393397
it('calls onChange function returning the beginning of the selected period when returnValue is set to "start"', () => {
394398
const onChange = jest.fn();
395-
const component = mount(
399+
const component = shallow(
396400
<Calendar
397401
onChange={onChange}
398402
returnValue="start"
@@ -407,7 +411,7 @@ describe('Calendar', () => {
407411

408412
it('calls onChange function returning the beginning of the selected period when returnValue is set to "start"', () => {
409413
const onChange = jest.fn();
410-
const component = mount(
414+
const component = shallow(
411415
<Calendar
412416
onChange={onChange}
413417
returnValue="start"
@@ -422,7 +426,7 @@ describe('Calendar', () => {
422426

423427
it('calls onChange function returning the end of the selected period when returnValue is set to "end"', () => {
424428
const onChange = jest.fn();
425-
const component = mount(
429+
const component = shallow(
426430
<Calendar
427431
onChange={onChange}
428432
returnValue="end"
@@ -437,7 +441,7 @@ describe('Calendar', () => {
437441

438442
it('calls onChange function returning the beginning of selected period when returnValue is set to "range"', () => {
439443
const onChange = jest.fn();
440-
const component = mount(
444+
const component = shallow(
441445
<Calendar
442446
onChange={onChange}
443447
returnValue="range"
@@ -455,7 +459,7 @@ describe('Calendar', () => {
455459

456460
it('calls onChange function returning the beginning of selected period, but no earlier than minDate', () => {
457461
const onChange = jest.fn();
458-
const component = mount(
462+
const component = shallow(
459463
<Calendar
460464
minDate={new Date(2017, 0, 1, 12)}
461465
onChange={onChange}
@@ -471,7 +475,7 @@ describe('Calendar', () => {
471475

472476
it('calls onChange function returning the beginning of selected period, but no later than maxDate', () => {
473477
const onChange = jest.fn();
474-
const component = mount(
478+
const component = shallow(
475479
<Calendar
476480
maxDate={new Date(2017, 0, 1, 12)}
477481
onChange={onChange}
@@ -487,7 +491,7 @@ describe('Calendar', () => {
487491

488492
it('calls onChange function returning the end of selected period, but no earlier than minDate', () => {
489493
const onChange = jest.fn();
490-
const component = mount(
494+
const component = shallow(
491495
<Calendar
492496
minDate={new Date(2017, 0, 2, 12)}
493497
onChange={onChange}
@@ -503,7 +507,7 @@ describe('Calendar', () => {
503507

504508
it('calls onChange function returning the end of selected period, but no later than maxDate', () => {
505509
const onChange = jest.fn();
506-
const component = mount(
510+
const component = shallow(
507511
<Calendar
508512
maxDate={new Date(2017, 0, 1, 12)}
509513
onChange={onChange}
@@ -519,7 +523,7 @@ describe('Calendar', () => {
519523

520524
it('calls onChange function returning a range when selected two pieces of a range', () => {
521525
const onChange = jest.fn();
522-
const component = mount(
526+
const component = shallow(
523527
<Calendar
524528
onChange={onChange}
525529
selectRange
@@ -539,7 +543,7 @@ describe('Calendar', () => {
539543

540544
it('calls onChange function returning a range when selected reversed two pieces of a range', () => {
541545
const onChange = jest.fn();
542-
const component = mount(
546+
const component = shallow(
543547
<Calendar
544548
onChange={onChange}
545549
selectRange
@@ -561,11 +565,12 @@ describe('Calendar', () => {
561565
it('changes Calendar view given new activeStartDate value', () => {
562566
const activeStartDate = new Date(2017, 0, 1);
563567
const newActiveStartDate = new Date(2018, 0, 1);
564-
const component = mount(
568+
const component = shallow(
565569
<Calendar activeStartDate={activeStartDate} />,
566570
);
567571

568572
component.setProps({ activeStartDate: newActiveStartDate });
573+
component.update();
569574

570575
const monthView = component.find('MonthView');
571576

0 commit comments

Comments
 (0)