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

stub method called async #17034

Merged
merged 1 commit into from Aug 11, 2017
Merged

stub method called async #17034

merged 1 commit into from Aug 11, 2017

Conversation

Bjvanminnen
Copy link
Contributor

We were occasionally seeing apps tests fail with something like:

TypeError: Attempted to assign to readonly property. (/Users/brent/git/cdo/apps/test/unit-tests.js:139316)

Looking at this line, it appeared to be this one https://github.com/code-dot-org/code-dot-org/blob/staging/apps/src/StudioApp.js#L1618.

StudioApp.init() adds a change handler to Blockly.mainWorkspace. I assume that what is happening is that sometimes some other test does something that causes this change handler to be called, we call updateBlockCount, and we fail because the element does not exist.

This might all be another indication that this isn't a great "unit" test. Ideally we would have a way of saying afterEach(() => cleanUpAllListeners()). In the absence of that, this might be the best we can do.

I can't be certain this fixes the problem, as I was hitting it very intermittently, but it seems like it should fix it.

Copy link
Member

@davidsbailey davidsbailey left a comment

Choose a reason for hiding this comment

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

Seems like a reasonable workaround, though I agree more strongly with your suggestion that StudioApp.init() may not really be very well suited to be unit tested in the first place. Let's keep in mind to try not unit testing this if problems continue.

// by stubbing the method that the listener calls.
sinon.stub(studioApp(), 'updateBlockCount').callsFake(
() => {});
studioApp().updateBlockCount();
Copy link
Member

Choose a reason for hiding this comment

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

presumably we don't need to call this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. That was there to test that things were stubbed correctly, and I didnt clean up everything correctly. Thanks for catching.

@Bjvanminnen
Copy link
Contributor Author

Given that this is an apps-test only change, and those have passed in my circle run, I'm going to merge this PR now.

@Bjvanminnen Bjvanminnen merged commit fad967c into staging Aug 11, 2017
@Bjvanminnen Bjvanminnen deleted the testFix branch August 11, 2017 22:37
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.

None yet

2 participants