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

testing stores #188

Closed
vid opened this issue Mar 11, 2015 · 3 comments
Closed

testing stores #188

vid opened this issue Mar 11, 2015 · 3 comments

Comments

@vid
Copy link

vid commented Mar 11, 2015

I want to test interaction with my stores (not the rest of components) at an integration level. I can't figure out how to mock or get around the HTTP state source's dependency on browser fetch. Is there any way to mock just this part of a test? Can Marty recognize it's not running in a browser and use an alternate fetch mechanism?

I see a discussion at #115 but there's no complete answer. I have tried mocking an HttpAPI instance without success and it's taking me off the supported path. Knowing 0.9 supports server rendering I'm wondering if there's a way to do this today.

Thanks!

@jhollingworth
Copy link
Contributor

Hey, there are a couple of strategies you could try

1) Stub StateSource#request (or StateSource#get/post/put/delete)

sinon.stub(SomeStateSource, "request").returns(Promise.resolve({
  body: {
    foo: { bar: "baz" }
  }
})

2) Uses sinon's fakeServer

docs

var expectedState = { bar: "baz" };
var server = sinon.fakeServer.create();

server.respondWith(
  "GET",
  "/foo",
  [200, { "Content-Type": "application/json" }, JSON.stringify(expectedState)]
);

FooStore.getFoo();

server.respond();

expect(FooStore.getFoo().result).to.eql(expectedState);

While a bit more complicated I prefer using fakeServer as it tests more.

@vid
Copy link
Author

vid commented Mar 11, 2015

thanks, I've been trying to work with those but still in the fog.

I've also been messing around with using sequence diagrams generated from http://bramp.github.io/js-sequence-diagrams/ but it struck me this would be really effective at the live, instrumented level. Have you considered that?

@jhollingworth
Copy link
Contributor

Thats a cool idea. I'd like to do something like that in the devtools but its just finding the time....

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

No branches or pull requests

2 participants