Uncaught Error: Assertion Failed: calling set on destroyed object

后端 未结 4 1172
旧巷少年郎
旧巷少年郎 2021-02-05 00:09

working in ember-cli testing. After all tests passed it returns extra two test with errors.

Uncaught Error: Assertion Failed: calling set on destroyed obj

相关标签:
4条回答
  • 2021-02-05 00:43

    I had a similar issue in an integration test. To resolve, in the integration test, I waited before performing the next action.

    import wait from 'ember-test-helpers/wait';
    wait().then(() => {
    // perform action (which previously used to cause an exception)
    });
    
    0 讨论(0)
  • 2021-02-05 00:45

    Ok i struggled with similar thing. So basically when you have "this.set()" inside a promise, it might happen that the promise takes too long to resolve, and the user already clicked away from that page, in this case you are trying to set something, that is already destroyed. I found the simplest solution to be just a simple check in the beginning of the promise.

    if (this.isDestroyed) {
        return;
    }
    this.set('...');
    ...
    

    Edit: alternatively you can use Ember.trySet.

    0 讨论(0)
  • 2021-02-05 00:58

    This is either because in the result of a promise or any other deferred code you do not check the destroy status of an object, or because you didn't teardown something that has been setup and interact with DOM events or anything external to the core of Ember.

    I used to have this especially on some jQuery plugins which I mapped to Ember, and during the tests the plugins were destroying too slowly and I was then either not using a run loop, or not checking the destroyed status of the Ember object I was manipulating.

    You can do so with:

    if ( !(obj.get('isDestroyed') || obj.get('isDestroying')) ) {
      // do your destroying code setting stuff
    }
    

    Also think about destroying any jQuery plugins that might have been initialised in the code of your views (anything setup in didInsertElement should be teardown in willDestroyElement for example).

    0 讨论(0)
  • 2021-02-05 01:07

    The issue is related to a promise not completely resolving and another test getting run immediately after.

    You should give Ember Concurrency a try.

    import { task, timeout } from 'ember-concurrency';

    myFunction: task(function * () {
    
      // do somethinng
    
      yield timeout(1000); // wait for x milliseconds
    
      // do something else
    
    }).drop(),
    
    0 讨论(0)
提交回复
热议问题