1
- 'use strict' ;
2
-
3
1
import React from 'react' ;
4
2
import ReactDom from 'react-dom' ;
5
- import TestUtils from 'react-addons- test-utils' ;
3
+ import ReactTestUtils from 'react-dom/ test-utils' ;
6
4
7
5
import chai from 'chai' ;
8
6
import sinon from 'sinon' ;
@@ -24,7 +22,7 @@ describe('Test of Notification', () => {
24
22
25
23
describe ( 'Notification component' , ( ) => {
26
24
it ( 'should have default properties' , function ( ) {
27
- component = TestUtils . renderIntoDocument ( < Notification title = 'test' /> ) ;
25
+ component = ReactTestUtils . renderIntoDocument ( < Notification title = 'test' /> ) ;
28
26
expect ( component . props . ignore ) . to . be . eql ( false ) ;
29
27
expect ( component . props . disableActiveWindow ) . to . be . eql ( false ) ;
30
28
expect ( component . props . askAgain ) . to . be . eql ( false ) ;
@@ -40,8 +38,8 @@ describe('Test of Notification', () => {
40
38
} ) ;
41
39
42
40
it ( 'should render dummy hidden tag' , function ( ) {
43
- component = TestUtils . renderIntoDocument ( < Notification title = 'test' /> ) ;
44
- const el = TestUtils . scryRenderedDOMComponentsWithTag ( component , 'input' ) ;
41
+ component = ReactTestUtils . renderIntoDocument ( < Notification title = 'test' /> ) ;
42
+ const el = ReactTestUtils . scryRenderedDOMComponentsWithTag ( component , 'input' ) ;
45
43
expect ( el . length ) . to . be . eql ( 1 ) ;
46
44
expect ( ReactDom . findDOMNode ( el [ 0 ] ) . type ) . to . be . eql ( 'hidden' ) ;
47
45
} ) ;
@@ -64,7 +62,7 @@ describe('Test of Notification', () => {
64
62
65
63
it ( 'should call notSupported prop' , ( ) => {
66
64
let spy = sinon . spy ( ) ;
67
- component = TestUtils . renderIntoDocument ( < Notification title = 'test' notSupported = { spy } /> ) ;
65
+ component = ReactTestUtils . renderIntoDocument ( < Notification title = 'test' notSupported = { spy } /> ) ;
68
66
expect ( spy . calledOnce ) . to . be . eql ( true ) ;
69
67
expect ( stub . called ) . to . be . eql ( false ) ;
70
68
} ) ;
@@ -79,10 +77,10 @@ describe('Test of Notification', () => {
79
77
before ( ( ) => {
80
78
spy1 = sinon . spy ( ) ;
81
79
spy2 = sinon . spy ( ) ;
82
- stub = sinon . stub ( window . Notification , 'requestPermission' , function ( cb ) {
80
+ stub = sinon . stub ( window . Notification , 'requestPermission' ) . callsFake ( function ( cb ) {
83
81
return cb ( PERMISSION_DENIED ) ;
84
82
} ) ;
85
- component = TestUtils . renderIntoDocument ( < Notification title = 'test' notSupported = { spy1 } onPermissionDenied = { spy2 } /> ) ;
83
+ component = ReactTestUtils . renderIntoDocument ( < Notification title = 'test' notSupported = { spy1 } onPermissionDenied = { spy2 } /> ) ;
86
84
} ) ;
87
85
88
86
after ( ( ) => {
@@ -107,11 +105,13 @@ describe('Test of Notification', () => {
107
105
before ( ( ) => {
108
106
spy1 = sinon . spy ( ) ;
109
107
spy2 = sinon . spy ( ) ;
110
- stub1 = sinon . stub ( window . Notification , 'permission' , { get : function ( ) { return PERMISSION_DENIED ; } } ) ;
111
- stub2 = sinon . stub ( window . Notification , 'requestPermission' , function ( cb ) {
108
+ stub1 = sinon . stub ( window . Notification , 'permission' ) . get ( function getterFn ( ) {
109
+ return PERMISSION_DENIED ;
110
+ } ) ;
111
+ stub2 = sinon . stub ( window . Notification , 'requestPermission' ) . callsFake ( function ( cb ) {
112
112
return cb ( PERMISSION_DENIED ) ;
113
113
} ) ;
114
- component = TestUtils . renderIntoDocument ( < Notification title = 'test' notSupported = { spy1 } onPermissionDenied = { spy2 } /> ) ;
114
+ component = ReactTestUtils . renderIntoDocument ( < Notification title = 'test' notSupported = { spy1 } onPermissionDenied = { spy2 } /> ) ;
115
115
} ) ;
116
116
117
117
after ( ( ) => {
@@ -138,11 +138,13 @@ describe('Test of Notification', () => {
138
138
spy1 = sinon . spy ( ) ;
139
139
spy2 = sinon . spy ( ) ;
140
140
spy3 = sinon . spy ( ) ;
141
- stub1 = sinon . stub ( window . Notification , 'permission' , { get : function ( ) { return PERMISSION_DENIED ; } } ) ;
142
- stub2 = sinon . stub ( window . Notification , 'requestPermission' , function ( cb ) {
141
+ stub1 = sinon . stub ( window . Notification , 'permission' ) . get ( function getterFn ( ) {
142
+ return PERMISSION_DENIED ;
143
+ } ) ;
144
+ stub2 = sinon . stub ( window . Notification , 'requestPermission' ) . callsFake ( function ( cb ) {
143
145
return cb ( PERMISSION_GRANTED ) ;
144
146
} ) ;
145
- component = TestUtils . renderIntoDocument ( < Notification title = 'test' notSupported = { spy1 } onPermissionDenied = { spy2 } onPermissionGranted = { spy3 } askAgain = { true } /> ) ;
147
+ component = ReactTestUtils . renderIntoDocument ( < Notification title = 'test' notSupported = { spy1 } onPermissionDenied = { spy2 } onPermissionGranted = { spy3 } askAgain = { true } /> ) ;
146
148
} ) ;
147
149
148
150
after ( ( ) => {
@@ -165,7 +167,7 @@ describe('Test of Notification', () => {
165
167
describe ( 'When Notification is granted' , ( ) => {
166
168
let stub ;
167
169
before ( ( ) => {
168
- stub = sinon . stub ( window . Notification , 'requestPermission' , function ( cb ) {
170
+ stub = sinon . stub ( window . Notification , 'requestPermission' ) . callsFake ( function ( cb ) {
169
171
return cb ( PERMISSION_GRANTED ) ;
170
172
} ) ;
171
173
} ) ;
@@ -180,7 +182,7 @@ describe('Test of Notification', () => {
180
182
spy1 = sinon . spy ( ) ;
181
183
spy2 = sinon . spy ( ) ;
182
184
spy3 = sinon . spy ( ) ;
183
- component = TestUtils . renderIntoDocument ( < Notification title = 'test' notSupported = { spy1 } onPermissionDenied = { spy2 } onPermissionGranted = { spy3 } /> ) ;
185
+ component = ReactTestUtils . renderIntoDocument ( < Notification title = 'test' notSupported = { spy1 } onPermissionDenied = { spy2 } onPermissionGranted = { spy3 } /> ) ;
184
186
} ) ;
185
187
186
188
it ( 'should call window.Notification.requestPermission' , ( ) => {
@@ -218,7 +220,7 @@ describe('Test of Notification', () => {
218
220
onErrorSpy = sinon . spy ( ) ;
219
221
220
222
it ( 'does not trigger Notification' , ( ) => {
221
- component = TestUtils . renderIntoDocument ( < Notification title = 'test' ignore = { true } onShow = { onShowSpy } onClick = { onClickSpy } onClose = { onCloseSpy } onError = { onErrorSpy } /> ) ;
223
+ component = ReactTestUtils . renderIntoDocument ( < Notification title = 'test' ignore = { true } onShow = { onShowSpy } onClick = { onClickSpy } onClose = { onCloseSpy } onError = { onErrorSpy } /> ) ;
222
224
expect ( stubConstructor . calledWithNew ( ) ) . to . be . eql ( false ) ;
223
225
expect ( onShowSpy . called ) . to . be . eql ( false ) ;
224
226
expect ( onClickSpy . called ) . to . be . eql ( false ) ;
@@ -242,7 +244,7 @@ describe('Test of Notification', () => {
242
244
onErrorSpy = sinon . spy ( ) ;
243
245
244
246
it ( 'trigger Notification with specified title and options' , ( ) => {
245
- component = TestUtils . renderIntoDocument ( < Notification title = { MY_TITLE } options = { MY_OPTIONS } ignore = { false } onShow = { onShowSpy } onClick = { onClickSpy } onClose = { onCloseSpy } onError = { onErrorSpy } /> ) ;
247
+ component = ReactTestUtils . renderIntoDocument ( < Notification title = { MY_TITLE } options = { MY_OPTIONS } ignore = { false } onShow = { onShowSpy } onClick = { onClickSpy } onClose = { onCloseSpy } onError = { onErrorSpy } /> ) ;
246
248
expect ( stubConstructor . calledWithNew ( ) ) . to . be . eql ( true ) ;
247
249
expect ( stubConstructor . calledWith ( MY_TITLE , MY_OPTIONS ) ) . to . be . eql ( true ) ;
248
250
} ) ;
0 commit comments