[tests][android] Remove android specific test logic as it now matches iOS

This commit is contained in:
Chris Bianca 2017-06-16 12:17:38 +01:00
parent 538b80a3f2
commit f2826683f6
2 changed files with 10 additions and 56 deletions

View File

@ -1,4 +1,3 @@
import { Platform } from 'react-native';
import should from 'should';
import sinon from 'sinon';
@ -90,10 +89,7 @@ function offTests({ describe, it, xcontext, context, firebase }) {
// Check childAddedCallback is really attached
await ref.push(DatabaseContents.DEFAULT.number);
// TODO: Android: There is definitely a single listener, but value is called three times
// rather than the two you'd perhaps expect
const expectedCount = Platform.OS === 'ios' ? 2 : 3;
valueCallback.should.be.callCount(expectedCount);
valueCallback.should.be.callCount(2);
childAddedCallback.should.be.callCount(arrayLength + 1);
// Returns nothing
@ -106,7 +102,7 @@ function offTests({ describe, it, xcontext, context, firebase }) {
await ref.push(DatabaseContents.DEFAULT.number);
// Callbacks should have been unbound and not called again
valueCallback.should.be.callCount(expectedCount);
valueCallback.should.be.callCount(2);
childAddedCallback.should.be.callCount(arrayLength + 1);
});
});
@ -267,10 +263,7 @@ function offTests({ describe, it, xcontext, context, firebase }) {
// Callback should have been called only once because one of the attachments
// has been removed
// TODO: Android: There is definitely a single listener, but value is called twice
// rather than the once you'd perhaps expect
const expectedCount = Platform.OS === 'ios' ? 3 : 4;
spyA.should.be.callCount(expectedCount);
spyA.should.be.callCount(3);
// Undo the second attachment
const resp2 = await ref.off('value', callbackA);
@ -280,7 +273,7 @@ function offTests({ describe, it, xcontext, context, firebase }) {
await ref.set(DatabaseContents.DEFAULT.number);
// Callback should not have been called any more times
spyA.should.be.callCount(expectedCount);
spyA.should.be.callCount(3);
});
});
});

View File

@ -1,23 +1,9 @@
import { Platform } from 'react-native';
import sinon from 'sinon';
import 'should-sinon';
import Promise from 'bluebird';
import DatabaseContents from '../../../support/DatabaseContents';
/**
* On Android, some data types result in callbacks that get called twice every time
* they are updated. This appears to be behaviour coming from the Android Firebase
* library itself.
*
* See https://github.com/invertase/react-native-firebase/issues/92 for details
*/
const DATATYPES_WITH_DUPLICATE_CALLBACK_CALLS = [
'array',
'number',
];
function onTests({ describe, context, it, firebase, tryCatch }) {
describe('ref().on(\'value\')', () => {
// Documented Web API Behaviour
@ -92,12 +78,7 @@ function onTests({ describe, context, it, firebase, tryCatch }) {
// Assertions
callback.should.be.calledWith(newDataValue);
if (Platform.OS === 'android' && DATATYPES_WITH_DUPLICATE_CALLBACK_CALLS.includes(dataRef)) {
callback.should.be.calledThrice();
} else {
callback.should.be.calledTwice();
}
callback.should.be.calledTwice();
// Tear down
@ -171,12 +152,7 @@ function onTests({ describe, context, it, firebase, tryCatch }) {
...arrayAsObject,
[newElementRef.key]: 37,
});
if (Platform.OS === 'android') {
callback.should.be.calledThrice();
} else {
callback.should.be.calledTwice();
}
callback.should.be.calledTwice();
// Tear down
@ -251,13 +227,8 @@ function onTests({ describe, context, it, firebase, tryCatch }) {
callbackA.should.be.calledWith(newDataValue);
callbackB.should.be.calledWith(newDataValue);
if (Platform.OS === 'android' && DATATYPES_WITH_DUPLICATE_CALLBACK_CALLS.includes(dataRef)) {
callbackA.should.be.calledThrice();
callbackB.should.be.calledThrice();
} else {
callbackA.should.be.calledTwice();
callbackB.should.be.calledTwice();
}
callbackA.should.be.calledTwice();
callbackB.should.be.calledTwice();
// Tear down
@ -317,12 +288,7 @@ function onTests({ describe, context, it, firebase, tryCatch }) {
// Assertions
context.value.should.eql(newDataValue);
if (Platform.OS === 'android' && DATATYPES_WITH_DUPLICATE_CALLBACK_CALLS.includes(dataRef)) {
context.callCount.should.eql(3);
} else {
context.callCount.should.eql(2);
}
context.callCount.should.eql(2);
// Tear down
@ -389,12 +355,7 @@ function onTests({ describe, context, it, firebase, tryCatch }) {
// Assertions
context.value.should.eql(newDataValue);
if (Platform.OS === 'android' && DATATYPES_WITH_DUPLICATE_CALLBACK_CALLS.includes(dataRef)) {
context.callCount.should.eql(3);
} else {
context.callCount.should.eql(2);
}
context.callCount.should.eql(2);
// Tear down