Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to classes and ES6/esmodule TS compilation #62

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions __test__/amdModule.test.js

This file was deleted.

71 changes: 71 additions & 0 deletions __test__/city.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import City from '../src/city';

const executeAllTests = () => {
describe('constructor', () => {
test('constructs a city', () => {
const city = new City('Foo', 'XX', 'XX', null, null);

expect(city).not.toBeNull();
});
});

describe('withinStateAndCountry', () => {
test('it finds cities', () => {
const lookupResult = City.withinStateAndCountry('DL', 'IN');
const names = lookupResult.map((city) => city.name);

expect(names).toEqual([
'Alīpur',
'Bawāna',
'Central Delhi',
'Delhi',
'Deoli',
'East Delhi',
'Karol Bāgh',
'Najafgarh',
'Narela',
'New Delhi',
'North Delhi',
'North East Delhi',
'North West Delhi',
'Nāngloi Jāt',
'Pitampura',
'Rohini',
'South Delhi',
'South West Delhi',
'West Delhi',
]);
});
});

describe('withinCountry', () => {
test('it finds cities', () => {
const lookupResult = City.withinCountry('TV');
const names = lookupResult.map((city) => city.name);

expect(names).toEqual([
'Alapi Village',
'Asau Village',
'Fakaifou Village',
'Funafuti',
'Kulia Village',
'Niulakita',
'Savave Village',
'Tanrake Village',
'Toga Village',
]);
});
});

describe('all', () => {
test('it gets all cities', () => {
const result = City.all();

expect(result).not.toBeNull();
expect(result[0]).not.toEqual([]);
});
});
};

export default executeAllTests;
executeAllTests();
45 changes: 45 additions & 0 deletions __test__/country.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import Country from '../src/country';

const executeAllTests = () => {
describe('constructor', () => {
test('constructs a country', () => {
const country = new Country('Foo', '1', 'XX', 'FLAGEMOJI', '$', null, null, []);

expect(country).not.toBeNull();
});
});

describe('byIsoCode', () => {
test('it finds Canada', () => {
const lookupResult = Country.byIsoCode('CA');

expect(lookupResult).not.toBeNull();
expect(lookupResult!.name).toEqual('Canada');
expect(lookupResult!.isoCode).toEqual('CA');
});

test('it finds the USA', () => {
const lookupResult = Country.byIsoCode('US');

expect(lookupResult).not.toBeNull();
expect(lookupResult!.name).toEqual('United States');
expect(lookupResult!.isoCode).toEqual('US');
});

test('it returns null when not found', () => {
expect(Country.byIsoCode('XX')).toBeNull();
});
});

describe('all', () => {
test('it gets all countries', () => {
const result = Country.all();

expect(result).not.toBeNull();
expect(result[0]).not.toEqual([]);
});
});
};

export default executeAllTests;
executeAllTests();
Loading