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

Utilize promises in triggerMouseEvent and fixture.run #8

Merged
merged 3 commits into from
Feb 6, 2021

Conversation

kurkle
Copy link
Member

@kurkle kurkle commented Feb 5, 2021

With async triggerMouseEvent, the tests can be a lot cleaner, for example:

https://github.com/chartjs/Chart.js/blob/4491732ad59b7796ba04cae878fa804717e91c2f/test/specs/controller.bubble.tests.js#L293-L314

		it ('should handle default hover styles', function(done) {
			var chart = this.chart;
			var point = chart.getDatasetMeta(0).data[0];

			afterEvent(chart, 'mousemove', function() {
				expect(point.options.backgroundColor).toBe('#3187DD');
				expect(point.options.borderColor).toBe('#175A9D');
				expect(point.options.borderWidth).toBe(1);
				expect(point.options.radius).toBe(20 + 4);

				afterEvent(chart, 'mouseout', function() {
					expect(point.options.backgroundColor).toBe('rgb(100, 150, 200)');
					expect(point.options.borderColor).toBe('rgb(50, 100, 150)');
					expect(point.options.borderWidth).toBe(2);
					expect(point.options.radius).toBe(20);

					done();
				});
				jasmine.triggerMouseEvent(chart, 'mouseout', point);
			});
			jasmine.triggerMouseEvent(chart, 'mousemove', point);
		});

Can be written like:

		it ('should handle default hover styles', function(done) {
			var chart = this.chart;
			var point = chart.getDatasetMeta(0).data[0];

			await jasmine.triggerMouseEvent(chart, 'mousemove', point);
			expect(point.options.backgroundColor).toBe('#3187DD');
			expect(point.options.borderColor).toBe('#175A9D');
			expect(point.options.borderWidth).toBe(1);
			expect(point.options.radius).toBe(20 + 4);

			await jasmine.triggerMouseEvent(chart, 'mouseout', point);
			expect(point.options.backgroundColor).toBe('rgb(100, 150, 200)');
			expect(point.options.borderColor).toBe('rgb(50, 100, 150)');
			expect(point.options.borderWidth).toBe(2);
			expect(point.options.radius).toBe(20);
		});

And a fixture run script like:

    run: (chart, done) => {
      var elem = chart.getDatasetMeta(0).data[0];
      afterEvent(chart, 'mousemove', () => {
        done();
      });
      triggerMouseEvent(chart, 'mousemove', elem.tooltipPosition());
    }

Would become

  run: (chart) => {
    var elem = chart.getDatasetMeta(0).data[0];
    return triggerMouseEvent(chart, 'mousemove', elem.tooltipPosition());
  }

@kurkle kurkle added enhancement New feature or request breaking change labels Feb 5, 2021
@kurkle kurkle merged commit 9ad35bf into chartjs:master Feb 6, 2021
@kurkle kurkle deleted the async branch February 10, 2021 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants