Commit e317e922 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Improve assertion on mock to include parameter

This makes it assert that the function is called with the
intended parameter.

Might fix flakiness of this test.
parent 77ce59ee
...@@ -62,7 +62,7 @@ describe('LazyLoader', function() { ...@@ -62,7 +62,7 @@ describe('LazyLoader', function() {
waitForAttributeChange(newImg, ['data-src', 'src']), waitForAttributeChange(newImg, ['data-src', 'src']),
]) ])
.then(() => { .then(() => {
expect(LazyLoader.loadImage).toHaveBeenCalled(); expect(LazyLoader.loadImage).toHaveBeenCalledWith(newImg);
expect(newImg.getAttribute('src')).toBe(testPath); expect(newImg.getAttribute('src')).toBe(testPath);
expect(newImg).toHaveClass('js-lazy-loaded'); expect(newImg).toHaveClass('js-lazy-loaded');
done(); done();
...@@ -79,7 +79,7 @@ describe('LazyLoader', function() { ...@@ -79,7 +79,7 @@ describe('LazyLoader', function() {
scrollIntoViewPromise(newImg) scrollIntoViewPromise(newImg)
.then(waitForPromises) .then(waitForPromises)
.then(() => { .then(() => {
expect(LazyLoader.loadImage).not.toHaveBeenCalled(); expect(LazyLoader.loadImage).not.toHaveBeenCalledWith(newImg);
expect(newImg).not.toHaveClass('js-lazy-loaded'); expect(newImg).not.toHaveClass('js-lazy-loaded');
done(); done();
}) })
...@@ -98,7 +98,7 @@ describe('LazyLoader', function() { ...@@ -98,7 +98,7 @@ describe('LazyLoader', function() {
scrollIntoViewPromise(newImg) scrollIntoViewPromise(newImg)
.then(waitForPromises) .then(waitForPromises)
.then(() => { .then(() => {
expect(LazyLoader.loadImage).not.toHaveBeenCalled(); expect(LazyLoader.loadImage).not.toHaveBeenCalledWith(newImg);
expect(newImg).not.toHaveClass('js-lazy-loaded'); expect(newImg).not.toHaveClass('js-lazy-loaded');
done(); done();
}) })
...@@ -121,7 +121,7 @@ describe('LazyLoader', function() { ...@@ -121,7 +121,7 @@ describe('LazyLoader', function() {
]) ])
.then(waitForPromises) .then(waitForPromises)
.then(() => { .then(() => {
expect(LazyLoader.loadImage).toHaveBeenCalled(); expect(LazyLoader.loadImage).toHaveBeenCalledWith(newImg);
expect(newImg).toHaveClass('js-lazy-loaded'); expect(newImg).toHaveClass('js-lazy-loaded');
done(); done();
}) })
...@@ -156,7 +156,7 @@ describe('LazyLoader', function() { ...@@ -156,7 +156,7 @@ describe('LazyLoader', function() {
Promise.all([scrollIntoViewPromise(img), waitForAttributeChange(img, ['data-src', 'src'])]) Promise.all([scrollIntoViewPromise(img), waitForAttributeChange(img, ['data-src', 'src'])])
.then(() => { .then(() => {
expect(LazyLoader.loadImage).toHaveBeenCalled(); expect(LazyLoader.loadImage).toHaveBeenCalledWith(img);
expect(img.getAttribute('src')).toBe(originalDataSrc); expect(img.getAttribute('src')).toBe(originalDataSrc);
expect(img).toHaveClass('js-lazy-loaded'); expect(img).toHaveClass('js-lazy-loaded');
done(); done();
...@@ -176,7 +176,7 @@ describe('LazyLoader', function() { ...@@ -176,7 +176,7 @@ describe('LazyLoader', function() {
waitForAttributeChange(newImg, ['data-src', 'src']), waitForAttributeChange(newImg, ['data-src', 'src']),
]) ])
.then(() => { .then(() => {
expect(LazyLoader.loadImage).toHaveBeenCalled(); expect(LazyLoader.loadImage).toHaveBeenCalledWith(newImg);
expect(newImg.getAttribute('src')).toBe(testPath); expect(newImg.getAttribute('src')).toBe(testPath);
expect(newImg).toHaveClass('js-lazy-loaded'); expect(newImg).toHaveClass('js-lazy-loaded');
done(); done();
...@@ -193,7 +193,7 @@ describe('LazyLoader', function() { ...@@ -193,7 +193,7 @@ describe('LazyLoader', function() {
scrollIntoViewPromise(newImg) scrollIntoViewPromise(newImg)
.then(waitForPromises) .then(waitForPromises)
.then(() => { .then(() => {
expect(LazyLoader.loadImage).not.toHaveBeenCalled(); expect(LazyLoader.loadImage).not.toHaveBeenCalledWith(newImg);
expect(newImg).not.toHaveClass('js-lazy-loaded'); expect(newImg).not.toHaveClass('js-lazy-loaded');
done(); done();
}) })
...@@ -212,7 +212,7 @@ describe('LazyLoader', function() { ...@@ -212,7 +212,7 @@ describe('LazyLoader', function() {
scrollIntoViewPromise(newImg) scrollIntoViewPromise(newImg)
.then(waitForPromises) .then(waitForPromises)
.then(() => { .then(() => {
expect(LazyLoader.loadImage).not.toHaveBeenCalled(); expect(LazyLoader.loadImage).not.toHaveBeenCalledWith(newImg);
expect(newImg).not.toHaveClass('js-lazy-loaded'); expect(newImg).not.toHaveClass('js-lazy-loaded');
done(); done();
}) })
...@@ -234,7 +234,7 @@ describe('LazyLoader', function() { ...@@ -234,7 +234,7 @@ describe('LazyLoader', function() {
waitForAttributeChange(newImg, ['data-src', 'src']), waitForAttributeChange(newImg, ['data-src', 'src']),
]) ])
.then(() => { .then(() => {
expect(LazyLoader.loadImage).toHaveBeenCalled(); expect(LazyLoader.loadImage).toHaveBeenCalledWith(newImg);
expect(newImg).toHaveClass('js-lazy-loaded'); expect(newImg).toHaveClass('js-lazy-loaded');
done(); done();
}) })
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment