aboutsummaryrefslogtreecommitdiff
path: root/test/modules/science.spec.ts
blob: 268da08ff80b97f1a3909a7480d384ee4be8f6b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { describe, expect, it } from 'vitest';
import { faker } from '../../src';
import { seededTests } from '../support/seeded-runs';
import { times } from './../support/times';

const NON_SEEDED_BASED_RUN = 5;

describe('science', () => {
  seededTests(faker, 'science', (t) => {
    t.itEach('chemicalElement', 'unit');
  });

  describe.each(times(NON_SEEDED_BASED_RUN).map(() => faker.seed()))(
    'random seeded tests for seed %i',
    () => {
      describe(`chemicalElement()`, () => {
        it('should return an object', () => {
          const name = faker.science.chemicalElement();

          expect(name).toBeTypeOf('object');
        });

        it('should return a valid element name when referenced into', () => {
          const name = faker.science.chemicalElement().name;

          expect(name).toBeTypeOf('string');
          expect(() => {
            faker.definitions.science.chemical_element.find(
              (element) => element.name === name
            );
          }).toBeTruthy();
        });

        it('should return a valid element symbol when referenced into', () => {
          const symbol = faker.science.chemicalElement().symbol;

          expect(symbol).toBeTypeOf('string');
          expect(() => {
            faker.definitions.science.chemical_element.find(
              (element) => element.symbol === symbol
            );
          }).toBeTruthy();
        });

        it('should return a valid element atomic number when referenced into', () => {
          const atomicNumber = faker.science.chemicalElement().atomicNumber;

          expect(atomicNumber).toBeTypeOf('number');
          expect(() => {
            faker.definitions.science.chemical_element.find(
              (element) => element.atomicNumber === atomicNumber
            );
          }).toBeTruthy();
        });
      });

      describe(`unit()`, () => {
        it('should return an object', () => {
          const unit = faker.science.unit();

          expect(unit).toBeTypeOf('object');
        });

        it('should return a valid unit name when referenced into', () => {
          const name = faker.science.unit().name;

          expect(name).toBeTypeOf('string');
          expect(() => {
            faker.definitions.science.unit.find((unit) => unit.name === name);
          }).toBeTruthy();
        });

        it('should return a valid unit symbol when referenced into', () => {
          const symbol = faker.science.unit().symbol;

          expect(symbol).toBeTypeOf('string');
          expect(() => {
            faker.definitions.science.unit.find(
              (unit) => unit.symbol === symbol
            );
          }).toBeTruthy();
        });
      });
    }
  );
});