Skip to content

Instantly share code, notes, and snippets.

@lupomontero
Created July 6, 2018 13:08
Show Gist options
  • Save lupomontero/5eff8bb2572fed7dd82a7364e8afef47 to your computer and use it in GitHub Desktop.
Save lupomontero/5eff8bb2572fed7dd82a7364e8afef47 to your computer and use it in GitHub Desktop.
const { uniq, pluck, extractCampus } = require('./');
describe('uniq', () => {
it('debería retornar un nuevo array sin elementos repetidos', () => {
expect(uniq(['a', 'a', 'z', 'a', true, 0])).toEqual(['a', 'z', true, 0]);
expect(uniq([1, 1, 1])).toEqual([1]);
});
});
describe('pluck', () => {
it('debería crear un nuevo arreglo con los valores de la propiedad especificada de cada objeto', () => {
expect(pluck([
{ name: 'lulu' },
{ name: 'amalia' },
{ name: 'steph' },
], 'name')).toEqual(['lulu', 'amalia', 'steph']);
});
});
describe('extractCampus', () => {
it('debería extraer la parte del campus de la propiedad `id` de cada cohort', () => {
expect(extractCampus(pluck([
{ id: 'lim-2018-05-bc-js-am' },
{ id: 'lim-2018-05-bc-js-pm' },
{ id: 'cdmx-2018-05-bc-js-am' },
], 'id'))).toEqual(['lim', 'lim', 'cdmx']);
});
it('debería poder combinarse con `uniq`', () = {
expect(uniq(extractCampus(pluck([
{ id: 'lim-2018-05-bc-js-am' },
{ id: 'lim-2018-05-bc-js-pm' },
{ id: 'cdmx-2018-05-bc-js-am' },
], 'id')))).toEqual(['lim', 'cdmx']);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment