Skip to content

Instantly share code, notes, and snippets.

@medunla
medunla / calculateGrade.js
Created June 13, 2021 17:06
Unit test example - calculateGrade.js with handle invalid cases
const calculateGrade = (score) => {
if (typeof score === "number"
&& score <= 100
&& score >= 0
) {
if (score >= 80) {
return "A";
} else if (score >= 70) {
return "B";
} else if (score >= 60) {
@medunla
medunla / calculateGrade.js
Last active June 13, 2021 17:01
Unit test example - calculateGrade.js without handle invalid cases
const calculateGrade = (score) => {
if (score >= 80) {
return "A";
} else if (score >= 70) {
return "B";
} else if (score >= 60) {
return "C";
} else if (score >= 50) {
return "D";
} else if (score < 50) {
@medunla
medunla / calculateGrade.test.js
Created June 13, 2021 16:42
Unit test example - calculateGrade.test.js with invalid cases
import calculateGrade from "../assets/js/calculateGrade";
describe("calculateGrade", () => {
describe("valid cases", () => {
describe("when score 80 - 100", () => {
it("should return 'A'", () => {
const result = calculateGrade(80);
const result2 = calculateGrade(100);
expect(result).toBe("A");
@medunla
medunla / calculateGrade.test.js
Created June 13, 2021 16:25
Unit test example - calculateGrade.test.js without invalid cases
import calculateGrade from "../assets/js/calculateGrade";
describe("calculateGrade", () => {
describe("when score 80 - 100", () => {
it("should return 'A'", () => {
const result = calculateGrade(80);
const result2 = calculateGrade(100);
expect(result).toBe("A");
expect(result2).toBe("A");
@medunla
medunla / mouse.svg
Created August 4, 2020 17:20
SVG animation - mouse
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@medunla
medunla / example-v-if-02.vue
Created June 10, 2020 11:46
example v-if 2
<template>
<template v-if="list.length > 0">
<h1>สิ่งที่ฉันชอบ</h1>
<ul>
<li v-for="listItem in list" :key="listItem">{{ listItem }}</li>
</ul>
</template>
<template v-else>
<h1>ไม่มีสิ่งที่ชอบ</h1>
<img src="/images/no-item.png" alt="No item">
<template>
<div v-if="list.length > 0">
<h1>สิ่งที่ฉันชอบ</h1>
<ul>
<li v-for="listItem in list" :key="listItem">{{ listItem }}</li>
</ul>
</div>
<div v-else>
<h1>ไม่มีสิ่งที่ชอบ</h1>
<img src="/images/no-item.png" alt="No item">
@medunla
medunla / align-with-flexbox-2.html
Created October 17, 2018 15:21
Align with CSS Flexbox - Step 2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Flexbox</title>
<style>
.container {
width: 300px;
@medunla
medunla / align-with-flexbox-1.html
Last active October 17, 2018 15:20
Align with CSS Flexbox - Step 1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Flexbox</title>
<style>
.container {
width: 300px;