Skip to content

Commit

Permalink
Merge 2a38e33 into 5873537
Browse files Browse the repository at this point in the history
  • Loading branch information
daybrush committed Dec 1, 2020
2 parents 5873537 + 2a38e33 commit 45bcfad
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/loaders/ImageLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ export default class ImageLoader extends Loader<HTMLImageElement> {
public static EVENTS = ["load", "error"];
public checkElement() {
const element = this.element;
if (element.complete && (!IS_IE || !!element.naturalWidth)) {
const src = element.getAttribute("src");
if (element.complete && src) {
if (!element.naturalWidth) {
this.onAlreadyError(this.element);
this.onAlreadyError(element);
}
return false;
}
this.addEvents();
IS_IE && element.setAttribute("src", element.getAttribute("src") as string);
IS_IE && element.setAttribute("src", src!);
return true;
}
}
35 changes: 33 additions & 2 deletions test/unit/Image.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sandbox, cleanup, waitEvent, getSize, checkEventOrders, expectOrders } from "./utils";
import { sandbox, cleanup, waitEvent, getSize, checkEventOrders, expectOrders, waitFor } from "./utils";
import ImReady from "../../src/index";
import { spy } from "sinon";
import { toArray, innerWidth, innerHeight } from "../../src/utils";
Expand Down Expand Up @@ -391,7 +391,7 @@ describe("Test image", () => {
expect(size1[1]).to.be.not.equals(size2[1]);

// ready
expect(size2[0]).to.be. equals(size3[0]);
expect(size2[0]).to.be.equals(size3[0]);
expect(size2[1]).to.be.not.equals(size3[1]);
});
it("should check that AutoSizer works when data-fixed='height' and window height (400 => 600)", async () => {
Expand Down Expand Up @@ -436,4 +436,35 @@ describe("Test image", () => {
expect(height2).to.be.equals(height3);
expect(width2).to.be.not.equals(width3);
});
it("should check whether the image of empty src is checked even if it is complete", async () => {
// Given
el.innerHTML = `<img />`;

const img = el.querySelector("img");

Object.defineProperty(img, "complete", {
value: true,
});
const events = checkEventOrders(im);

// When
im.check([el]);

// The ready event does not occur immediately.
await waitFor(100);

const isReady1 = im.isReady();
img.src = "https://naver.github.io/egjs-infinitegrid/assets/image/22.jpg";

await waitEvent(im, "ready");
const isReady2 = im.isReady();

// Then
expect(isReady1).to.be.false;
expect(isReady2).to.be.true;
expectOrders(events, [
"preReadyElement", "readyElement",
"preReady", "ready",
]);
});
});

0 comments on commit 45bcfad

Please sign in to comment.