RealOrangeOne / react-native-mock

A fully mocked and test-friendly version of react native (maintainers wanted)
MIT License
571 stars 153 forks source link

fixed the check for duplicate route being pushed #84

Closed winkerVSbecks closed 8 years ago

winkerVSbecks commented 8 years ago

Noticed that there is an issue with NavigationStateUtils.push method. In the original react-native version you will notice that it uses invariant check for indexOf(state, route.key) === -1:

function push(state: NavigationState, route: NavigationRoute): NavigationState {
  invariant(
    indexOf(state, route.key) === -1,
    'should not push route with duplicated key %s',
    route.key,
  );
...
}

Where as the react-native-mock version throws an error if indexOf(state, route.key) === -1 is true:

function push(state, route) {
  if (indexOf(state, route.key) === -1) {
    throw new Error('should not push route with duplicated key ' + route.key);
  }
...
}

Invariant throws an error for falsy values (https://github.com/zertosh/invariant#invariantcondition-message). Therefore the above should be: indexOf(state, route.key) !== -1

RealOrangeOne commented 8 years ago

Duplicate of #81, closing