Skip to content

Instantly share code, notes, and snippets.

View haingdc's full-sized avatar

Hai.Nguyen Github haingdc

View GitHub Profile
@haingdc
haingdc / photo-lister02.js
Created April 10, 2018 03:02
Thao tác với DOM thông qua TDD
// photo-lister.js
PhotoLister = {
photoToListItem: function(photo) {
return (
'<li><figure><img src="' +
photo.url +
'" alt=""/>' +
"<figcaption>" +
photo.title +
"</figcaption></figure></li>"
@haingdc
haingdc / photo-lister-spec02.js
Last active April 10, 2018 03:20
Thao tác với DOM thông qua TDD
// photo-lister-spec.js
describe("#photoToListItem()", function() {
it("should take a photo object and return a list item string", function() {
var input = {
title: "This is a test",
url: "http://loremflickr.com/960/593",
},
expected =
'<li><figure><img src="http://loremflickr.com/960/593" alt=""/>' +
"<figcaption>This is a test</figcaption></figure></li>";
@haingdc
haingdc / photo-lister01.js
Created April 10, 2018 03:00
Thao tác với DOM thông qua TDD
// photo-lister.js
PhotoLister = {
photoToListItem: function() {
return (
'<li><figure><img src="http://loremflickr.com/960/593" alt=""/>' +
"<figcaption>This is a test</figcaption></figure></li>"
);
},
};
@haingdc
haingdc / photo-lister00.js
Last active April 10, 2018 02:59
Thao tác với DOM thông qua TDD
// photo-lister.js
var PhotoLister;
PhotoLister = {
photoToListItem: function() {}
};
module.exports = PhotoLister;
@haingdc
haingdc / photo-lister-spec01.js
Last active April 10, 2018 02:59
Thao tác với DOM thông qua TDD
// photo-lister-spec.js
describe("#photoToListItem()", function() {
it("should take a photo object and return a list item string", function() {
var input = {
title: "This is a test",
url: "http://loremflickr.com/960/593",
},
expected =
'<li><figure><img src="http://loremflickr.com/960/593" alt=""/>' +
"<figcaption>This is a test</figcaption></figure></li>";
@haingdc
haingdc / photo-lister-spec00.js
Created April 10, 2018 02:55
Thao tác với DOM thông qua TDD
// photo-lister-spec.js
var expect = require("chai").expect,
PhotoLister = require("./photo-lister");
describe("PhotoLister", function() {
it("should exist", function() {
expect(PhotoLister).not.to.be.undefined;
});
});
@haingdc
haingdc / flickr-fetcher-spec.js
Created April 4, 2018 08:21
Gửi các request tới server thông qua TDD
// flickr-fetcher-spec.js
describe("#fetchFlickrData()", function() {
it("should take an API key and fetcher function argument and return a promise for JSON data.", function() {
var apiKey = "does not matter much what this is right now",
fakeData = {
photos: {
page: 1,
pages: 2872,
perpage: 100,
total: "287170",
@haingdc
haingdc / flickr-fetcher.js
Created April 4, 2018 08:16
Gửi các request tới server thông qua TDD
fetchPhotos: function(apiKey, fetch) {
return FlickrFetcher.fetchFlickrData(apiKey, fetch).then(function(data) {
return data.photos.photo.map(FlickrFetcher.transformPhotoObj);
});
}
@haingdc
haingdc / flickr-fetcher-spec.js
Created April 4, 2018 08:14
Gửi các request tới server thông qua TDD
describe("#fetchPhotos()", function() {
it("should take an API key and fetcher function, and return a promise for transformed photos", function() {
var apiKey = "does not matter what this is right now",
expected = [
{
title: "Dog goes to desperate measure to avoid walking on a leash",
url:
"https://farm2.staticflickr.com/1669/25373736106_146731fcb7_b.jpg",
},
@haingdc
haingdc / flickr-fetcher.js
Created April 4, 2018 08:12
Gửi các request tới server thông qua TDD
// flickr-fetcher.js
fetchFlickrData: function(apiKey, fetch) {
var url = 'https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key='
+ apiKey + '&text=pugs&format=json&nojsoncallback=1'
return fetch(url);
}