Skip to content

Instantly share code, notes, and snippets.

@azangru
azangru / Container.test.tsx
Last active May 2, 2019 10:29
React testing example
import React from 'react';
import { mount } from 'enzyme';
import apiService from 'src/services/api-service';
apiService.fetch = jest.fn(() => Promise.resolve([{ name: 'foo' }]));
import Container from './Container';
import Form from '../form/Form';
import Results from '../results/Results';
describe('Checkin Repository', () => {
let checkinRepository, httpBackend;
beforeEach(() => {
module('app');
});
beforeEach(inject(($httpBackend, checkinDeviceRepository) => {
httpBackend = $httpBackend;
@azangru
azangru / flatten.js
Last active August 29, 2015 14:22
Flatten for underbar — recursive
// By the way — no idea why the function definition contains 'result' as a second argument;
// this is not present in the Underscore library.
_.flatten = function(nestedArray, result) {
var resultingArray = [];
_.each(nestedArray, function(element, index, nestedArray){
flattenHelper(element, resultingArray);
});
return resultingArray;
};