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

Recreate golden with this before each test #41

Merged
merged 5 commits into from
Jun 26, 2023
Merged

Recreate golden with this before each test #41

merged 5 commits into from
Jun 26, 2023

Conversation

bearfriend
Copy link
Contributor

@bearfriend bearfriend commented Jun 24, 2023

Adds a beforeEach root hook to mocha, in which the golden assertion method is recreated to call ScreenshotAndCompare with the current test and fixture element in this.

Avoids needing to pass this to golden(), which also allows arrow functions to be used.

@bearfriend bearfriend requested a review from a team as a code owner June 24, 2023 01:33
Copy link
Member

@dlockhart dlockhart left a comment

Choose a reason for hiding this comment

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

Whoa, this is super cool! Makes things so much cleaner.

beforeEach() {
const { currentTest } = this;
chai.Assertion.addMethod('golden', function(...args) {
return ScreenshotAndCompare.call({ test: currentTest, elem: this._obj }, ...args); // eslint-disable-line no-invalid-this
Copy link
Member

Choose a reason for hiding this comment

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

I guess this._obj is a Chai thing eh, like it's whatever you call expect(thing).to.be.whatever with?

src/browser/vdiff.js Outdated Show resolved Hide resolved
Copy link
Member

@dlockhart dlockhart left a comment

Choose a reason for hiding this comment

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

Amazing!

@bearfriend bearfriend merged commit 8906eb7 into main Jun 26, 2023
@bearfriend bearfriend deleted the mocha-this branch June 26, 2023 17:35
@ghost
Copy link

ghost commented Jun 26, 2023

🎉 This PR is included in version 0.12.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ghost ghost added the released label Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants