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

ReactNative compatibility. Allow sinon fakeServer to run in React Native #1052

Merged
merged 7 commits into from
Jun 4, 2016
Merged

Conversation

andpor
Copy link
Contributor

@andpor andpor commented May 26, 2016

Purpose (TL;DR) - mandatory

Enable fakeServer to execute in ReactNative environment - #1051

Background (Problem in detail) - optional

React Native has xhr support via polyfill but sinon is not detecting it properly
React Native does not have window.location - it needs to be detected and defaulted properly

Solution - optional

Proper check for xhr support in ReactNative env
Default window.location if it is undefined

How to verify - mandatory

  1. Create react native sample app. Look at RN getting started
  2. Add sinon as dependency in package.json, run npm install
  3. Require sinon
  4. Code fakeServer test cases in RN app
  5. Run all normal test cases to verify no regression.

andpor added 5 commits May 26, 2016 11:38
…ve environment either on device or browser debug.

ReactNative has xhr support via polyfill. But the check for supporting xhr looked and withEntitlements which is failing in RN.

ReactNative does not have window.location so a default assignment and check for undefined window.location was needed.
@andpor andpor changed the title ReactNative compatibility. Allow sign fakeServer to run in React Nati… ReactNative compatibility. Allow signon fakeServer to run in React Nati… May 26, 2016
@andpor andpor changed the title ReactNative compatibility. Allow signon fakeServer to run in React Nati… ReactNative compatibility. Allow sinon fakeServer to run in React Native May 26, 2016
@@ -33,6 +33,7 @@ function responseArray(handler) {
}

var wloc = typeof window !== "undefined" ? window.location : {};
wloc = typeof wloc !== "undefined" ? wloc : { "host" : "localhost", "protocol" : "http"};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 35 and 36 could be squashed into one line. You are guaranteed that wloc is defined.

var wloc = typeof window !== "undefined" ? window.location : { "host" : "localhost", "protocol" : "http"};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do that tomorrow.

@fatso83
Copy link
Contributor

fatso83 commented May 27, 2016

I think this is fine, but could you just compress the two lines mentioned? I am also going to squash these commits into one, unless you do it yourself, as a final step.

@andpor
Copy link
Contributor Author

andpor commented May 30, 2016

Change is done. Please squash.

@fatso83 fatso83 merged commit 82d2a7c into sinonjs:master Jun 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants