fix: adjust test cases

This commit is contained in:
Richie 2021-05-15 10:26:46 +08:00
parent b6c3b0d319
commit e190066be6
2 changed files with 10 additions and 4 deletions

View File

@ -84,7 +84,9 @@ describe('NfcManager (ios)', () => {
NfcManager.setEventListener(NfcEvents.SessionClosed, () => {
sessionClosed = true;
});
NfcManagerEmitter._testTriggerCallback(NfcEvents.SessionClosed);
NfcManagerEmitter._testTriggerCallback(NfcEvents.SessionClosed, {
error: 'NFCError:200',
});
expect(sessionClosed).toBe(true);
});
@ -107,7 +109,7 @@ describe('NfcManager (ios)', () => {
// default can be overriden by throwOnError
await NfcManager.cancelTechnologyRequest({throwOnError: true});
} catch (ex) {
expect(ex).toEqual('fake-error-again');
expect(ex.message).toEqual('fake-error-again');
}
});

View File

@ -1,10 +1,12 @@
let _nextError = null;
let _nextErrorMethod = null;
const NativeNfcManager = {
MIFARE_BLOCK_SIZE: 16,
MIFARE_ULTRALIGHT_PAGE_SIZE: 4,
setNextError: (err) => {
setNextError: (err, nativeMethodName = null) => {
_nextError = err;
_nextErrorMethod = nativeMethodName;
},
};
@ -20,9 +22,11 @@ const NfcManagerEmitter = {
};
const callNative = jest.fn((...args) => {
if (_nextError) {
const [methodName, ...rest] = args;
if (_nextError && (!methodName || methodName === _nextErrorMethod)) {
const err = _nextError;
_nextError = null;
_nextErrorMethod = null;
return Promise.reject(err);
}
});