Ember-auth QUnit tests fail every second run

情到浓时终转凉″ 提交于 2020-01-04 04:45:16

问题


I have recently managed to get my ember-auth tests to pass, but it's not yet perfect, as the tests fail every second time (or if there are several tests running, every second test about authentication fails).

I have created a small sample app to demonstrate the failure.

You should be able to reproduce the failure by following these steps:

1. git clone https://github.com/pedrokost/ember_auth_testing_example.git
2. cd ember_auth_testing_example
3. ruby -run -e httpd . -p5000 # (or any HTTP server like: python -m SimpleHTTPServer)
4. Open http://localhost:5000?test in the browser

If the tests passes, refresh the page and see it fail with "Invalid JSON format". Next time you refresh it works again.


回答1:


I had this exact problem when using local storage to save my session. This is because the ember-testing does not clear local storage by default. There are at least three ways to solve this:

  1. Use ephemeral storage with Ember Auth
  2. Add local storage deletion to your setup/tearDown functions
  3. Add Ember Auth logout to the tearDown function

The first solution seems to be the simplest and best solution since it's possible to set the storage to just for Ember Auth. The ember-auth documentation explains storage options:

Cookie

App.Auth = Em.Auth.extend 
   session: 'dummy'

Dummy (for unit tests)

App.Auth = Em.Auth.extend 
   session: 'cookie'

You would want to set yours to Dummy in your initialization if Ember.testing === true



来源:https://stackoverflow.com/questions/20934995/ember-auth-qunit-tests-fail-every-second-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!