Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enhance error checking #394

Merged
merged 9 commits into from
May 10, 2021
19 changes: 18 additions & 1 deletion __tests__/NfcManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import {
NfcManagerEmitter,
callNative,
} from '../src/NativeNfcManager';
import * as NfcError from '../src/NfcError';

describe('NfcManager (ios)', () => {
Platform.setOS('ios');
const NfcManagerModule = require('../src/index.js');
const NfcManager = NfcManagerModule.default;
const {NfcEvents, NfcErrorIOS} = NfcManagerModule;
const {NfcEvents, NfcErrorIOS, NfcTech} = NfcManagerModule;
const lastNativeCall = () =>
callNative.mock.calls[callNative.mock.calls.length - 1];

Expand Down Expand Up @@ -129,4 +130,20 @@ describe('NfcManager (ios)', () => {
NfcErrorIOS.errCodes.userCancel,
);
});

test('NfcError', async () => {
try {
NativeNfcManager.setNextError('NFCError:200');
await NfcManager.requestTechnology(NfcTech.Ndef);
} catch (ex) {
if (!(ex instanceof NfcError.UserCancel)) {
expect(true).toBe(false);
}

// for backward capatible
if (NfcErrorIOS.parse(ex) !== NfcErrorIOS.errCodes.userCancel) {
expect(true).toBe(false);
}
}
});
});
14 changes: 14 additions & 0 deletions __tests__/NfcManagerAndroid.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
jest.mock('../src/NativeNfcManager');

import {Platform} from 'react-native';
import {NativeNfcManager} from '../src/NativeNfcManager';
import * as NfcError from '../src/NfcError';

describe('NfcManager (android)', () => {
Platform.setOS('android');
const NfcManagerModule = require('../src/index.js');
const NfcManager = NfcManagerModule.default;
const {NfcTech} = NfcManagerModule;

test('constructor', () => {
expect(Platform.OS).toBe('android');
Expand Down Expand Up @@ -56,4 +59,15 @@ describe('NfcManager (android)', () => {
await NfcManager.setAlertMessage();
expect(true).toBe(true);
});

test('NfcError', async () => {
try {
NativeNfcManager.setNextError('cancelled');
await NfcManager.requestTechnology(NfcTech.Ndef);
} catch (ex) {
if (!(ex instanceof NfcError.UserCancel)) {
expect(true).toBe(false);
}
}
});
});
Loading