Hello all I am new in testing, I am just trying to test async storage value, it's set to 25 as you see;
This is test I have written as below;
test('can read asyncstorage', async () => { let val = await AsyncStorage.getItem('isFirst'); expect(val).toBe('25');});
The error I am getting is like below;
expect(received).toBe(expected) // Object.is equality Expected: "25" Received: null
Did I just misunderstood the concept of writing tests? should I set 25 with mocked setItem function just before calling getItem? If I do that (as below), it passes the test, would it be a right approach?
test('can read asyncstorage', async () => { await AsyncStorage.setItem('isSecond', '25'); let val = await AsyncStorage.getItem('isSecond'); expect(val).toBe('25');});
Or Is it right way to try to get real stored value and validate it?
This is how I mocked;
beforeAll(() => { jest.doMock('@react-native-async-storage/async-storage', () => { return { getItem: async (...args: any) => args, setItem: async (...args: any) => args, }; });});
Thank you.
Versions I use
"typescript": "^3.9.10""@types/react-native": "^0.64.10","@types/react-test-renderer": "^16.9.5",