This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type SnakeToCamelCase< | |
SnakeCaseWord extends string, | |
Result extends string = '' | |
> = Uncapitalize< | |
SnakeCaseWord extends `${infer Head}_${infer Tail}` | |
? SnakeToCamelCase<Tail, `${Result}${Capitalize<Head>}`> | |
: `${Result}${Capitalize<SnakeCaseWord>}` | |
>; | |
type CamelCaseObjectTypes<O extends object> = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sorts an array of object by ranking | |
* @param {array} objects The array containing objects to sort by ranking | |
*/ | |
function orderByRanking(objects) { | |
return objects.sort((a, b) => a.ranking - b.ranking); | |
} | |
/** | |
* Calculates the average ranking of objects |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// open all sections | |
$$('section.module:not(.open) header').forEach((h) => h.click()); | |
// get all list course videos in each section | |
let listItems = $$('section.module li'); | |
// download them | |
for (let i = 0; i < listItems.length; i++) { | |
let listItem = listItems[i]; | |
let title = listItem.querySelector('h3').textContent; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo { | |
constructor(x) { this.foo = x; } | |
hello() { console.log(this.foo); } | |
} | |
class Bar extends Foo { | |
constructor(x) { super(x); this.bar = x * 100; } | |
world() { console.log(this.bar); } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- Table structure for table `currency` | |
-- | |
CREATE TABLE IF NOT EXISTS `currency` ( | |
`iso` char(3) CHARACTER SET utf8 NOT NULL DEFAULT '', | |
`name` varchar(200) COLLATE utf8_unicode_ci NOT NULL, | |
PRIMARY KEY (`iso`), | |
UNIQUE KEY `name` (`name`) | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
// get the MockedProvider from react-apollo/test-utils | |
import { MockedProvider } from "react-apollo/test-utils"; | |
import { cleanup, render } from "react-testing-library"; | |
import UsersList, { GET_USERS_QUERY } from "./UserList"; | |
describe("UserList component", () => { | |
afterEach(cleanup); | |
const request = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('should render the loading component', () => { | |
const { getByText } = render( | |
// pass empty array to mocks prop | |
<MockedProvider mocks={[]}> | |
<UsersList /> | |
</MockedProvider> | |
); | |
// find loading component by text | |
const loader = getByText(/Loading/); | |
// check whether that it renders the right content |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
// get the MockedProvider from react-apollo/test-utils | |
import { MockedProvider } from "react-apollo/test-utils"; | |
import { cleanup, render } from "react-testing-library"; | |
// get the UserList component and GET_USERS_QUERY | |
// if the UserList file is in the same direcory as a file with the file containing the tests | |
import UsersList, { GET_USERS_QUERY } from "./UserList"; | |
describe("UserList component", () => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { render } from 'react-testing-library'; | |
import { ApolloProvider } from 'react-apollo'; | |
import client from './apolloClient'; | |
describe("UserList component", () => { | |
it("should render the list of users", () => { | |
// try rendering the UserList component in an ApolloProvider | |
const { getByText } = render( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { render } from 'react-testing-library'; | |
describe("UserList component", () => { | |
it("should render the list of users", () => { | |
// try rendering the UserList component | |
const { getByText } = render(<UsersList />); | |
}); | |
}); |
NewerOlder