1- import fetch from 'jest-fetch-mock' ;
21import checkVersion , { compareVersion } from '../src' ;
32import getIOSVersion from '../src/ios' ;
43import getAndroidVersion from '../src/android' ;
54
6- describe ( 'checkVersion' , ( ) => {
5+ require ( 'jest-fetch-mock' ) ;
6+
7+ describe ( 'ios' , ( ) => {
78 beforeEach ( ( ) => {
8- jest . mock ( 'Platform' , ( ) => ( { OS : 'ios' } ) ) ;
9- jest . mock ( 'fetch' , ( ) => fetch ) ;
10- jest . setTimeout ( 30000 ) ;
9+ jest . resetModules ( ) ;
10+ jest . mock ( 'react-native/Libraries/Utilities/Platform' , ( ) => ( {
11+ OS : 'ios' ,
12+ select : ( ) => null ,
13+ } ) ) ;
1114 } ) ;
1215
13- // it('ios correct pattern', async () => {
14- // jest.mock('Platform', () => ({ OS: 'ios' }));
15-
16- // const result = await checkVersion({
17- // version: '1.0.0',
18- // iosStoreURL: 'https://itunes.apple.com/app/id1321198947?mt=8',
19- // country: 'us',
20- // });
21-
22- // expect(result).toHaveProperty('local');
23- // expect(result).toHaveProperty('remote');
24- // expect(result).toHaveProperty('result', 'new');
25- // });
26-
27- // it('android correct pattern', async () => {
28- // jest.mock('Platform', () => ({ OS: 'android' }));
29-
30- // const result = await checkVersion({
31- // version: '100.0.0',
32- // iosStoreURL: 'https://play.google.com/store/apps/details?id=jp.ewaf.likedsearch.android',
33- // });
34-
35- // expect(result).toHaveProperty('local');
36- // expect(result).toHaveProperty('remote');
37- // expect(result).toHaveProperty('result', 'old');
38- // });
39-
4016 it ( 'error pattern' , async ( ) => {
41- const result = await checkVersion ( {
42- version : '1.0.0' ,
43- } ) ;
44-
45- expect ( result ) . toHaveProperty ( 'error' , true ) ;
17+ try {
18+ await checkVersion ( {
19+ version : '1.0.0' ,
20+ } ) ;
21+ } catch ( e ) {
22+ expect ( e . message ) . toBe ( 'iosStoreURL is not set.' ) ;
23+ }
4624 } ) ;
4725
48- it ( 'ios get version' , async ( ) => {
26+ it ( 'get version' , async ( ) => {
4927 const correctPattern = await getIOSVersion ( 'https://itunes.apple.com/jp/app/pin-point/id1321198947' ) ;
5028 expect ( correctPattern ) . toEqual ( expect . stringMatching ( / [ 0 - 9 ] { 1 , } \. ? [ 0 - 9 ] * \. ? [ 0 - 9 ] * \. ? / ) ) ;
5129
@@ -61,8 +39,28 @@ describe('checkVersion', () => {
6139 expect ( e ) . toHaveProperty ( 'message' ) ;
6240 }
6341 } ) ;
42+ } ) ;
43+
44+ describe ( 'android' , ( ) => {
45+ beforeEach ( ( ) => {
46+ jest . resetModules ( ) ;
47+ jest . mock ( 'react-native/Libraries/Utilities/Platform' , ( ) => ( {
48+ OS : 'android' ,
49+ select : ( ) => null ,
50+ } ) ) ;
51+ } ) ;
6452
65- it ( 'android get version' , async ( ) => {
53+ it ( 'error pattern' , async ( ) => {
54+ try {
55+ await checkVersion ( {
56+ version : '1.0.0' ,
57+ } ) ;
58+ } catch ( e ) {
59+ expect ( e . message ) . toBe ( 'androidStoreURL is not set.' ) ;
60+ }
61+ } ) ;
62+
63+ it ( 'get version' , async ( ) => {
6664 const correctPattern = await getAndroidVersion ( 'https://play.google.com/store/apps/details?id=jp.ewaf.likedsearch.android' ) ;
6765 expect ( correctPattern ) . toEqual ( expect . stringMatching ( / [ 0 - 9 ] { 1 , } \. ? [ 0 - 9 ] * \. ? [ 0 - 9 ] * \. ? / ) ) ;
6866
@@ -78,7 +76,9 @@ describe('checkVersion', () => {
7876 expect ( e ) . toHaveProperty ( 'message' ) ;
7977 }
8078 } ) ;
79+ } ) ;
8180
81+ describe ( 'other' , ( ) => {
8282 it ( 'compare version' , ( ) => {
8383 const remoteIsOld = compareVersion ( '1.1.0' , '1.0.3' ) ;
8484 expect ( remoteIsOld ) . toBe ( 'old' ) ;
0 commit comments