Skip to content

Instantly share code, notes, and snippets.

View qunabu's full-sized avatar

Mateusz Qunabu qunabu

View GitHub Profile
@qunabu
qunabu / t.js
Created November 26, 2020 10:30
describe("Saving the user profile", () => {
let profileModule;
beforeEach(() => {
jasmine.Ajax.install();
profileModule = new ProfileModule();
});
afterEach(() => {
jasmine.Ajax.uninstall();
@qunabu
qunabu / t.js
Created November 26, 2020 10:30
describe("Saving the user profile", () => {
let profileModule;
let notifyUserSpy;
let onCompleteSpy;
beforeEach(() => {
profileModule = new ProfileModule();
notifyUserSpy = spyOn(profileModule, "notifyUser");
onCompleteSpy = jasmine.createSpy();
});
@qunabu
qunabu / t.js
Created November 26, 2020 10:29
it("should multiply the number passed as parameter and subtract one", () => {
const result = Calculator.compute(21.5);
expect(result).toBe(42);
});
@qunabu
qunabu / t.js
Created November 26, 2020 10:29
it("should multiply the number passed as parameter and subtract one", () => {
const multiplySpy = spyOn(Calculator, "multiple").and.callThrough();
const subtractSpy = spyOn(Calculator, "subtract").and.callThrough();
const result = Calculator.compute(21.5);
expect(multiplySpy).toHaveBeenCalledWith(21.5, 2);
expect(subtractSpy).toHaveBeenCalledWith(43, 1);
expect(result).toBe(42);
});
@qunabu
qunabu / t.js
Created November 26, 2020 10:27
it("should properly sanitize strings", () => {
let result;
const testValues = {
Avion: "Avi" + String.fromCharCode(243) + "n",
"The-space": "The space",
"Weird-chars-": "Weird chars!!",
"file-name.zip": "file name.zip",
"my-name.zip": "my.name.zip",
};
@qunabu
qunabu / t.js
Created November 26, 2020 10:27
it("should sanitize a string containing non-ASCII chars", () => {
expect(sanitizeString("Avi" + String.fromCharCode(243) + "n")).toBe("Avion");
});
it("should sanitize a string containing spaces", () => {
expect(sanitizeString("The space")).toBe("The-space");
});
it("should sanitize a string containing exclamation signs", () => {
expect(sanitizeString("Weird chars!!")).toBe("Weird-chars-");
@qunabu
qunabu / t.js
Created November 26, 2020 10:26
it("should properly sanitize strings", () => {
expect(sanitizeString("Avi" + String.fromCharCode(243) + "n")).toBe("Avion");
expect(sanitizeString("The space")).toBe("The-space");
expect(sanitizeString("Weird chars!!")).toBe("Weird-chars-");
expect(sanitizeString("file name.zip")).toBe("file-name.zip");
expect(sanitizeString("my.name.zip")).toBe("my-name.zip");
});
@qunabu
qunabu / t.jh
Created November 26, 2020 10:26
it("should properly sanitize strings", () => {
let result;
const testValues = {
Avion: "Avi" + String.fromCharCode(243) + "n",
"The-space": "The space",
"Weird-chars-": "Weird chars!!",
"file-name.zip": "file name.zip",
"my-name.zip": "my.name.zip",
};
@qunabu
qunabu / t.js
Created November 26, 2020 10:25
// Good
describe("[unit of work]", () => {
it("should [expected behaviour] when [scenario/context]", () => {});
});
// Better
describe("[unit of work]", () => {
describe("when [scenario/context]", () => {
it("should [expected behaviour]", () => {});
});
@qunabu
qunabu / t.js
Created November 26, 2020 10:24
describe("The Gallery instance", () => {
it("should properly calculate the thumb size when initialized", () => {});
it("should properly calculate the thumbs count when initialized", () => {});
});