Welcome to mirror list, hosted at ThFree Co, Russian Federation.

props_utils_spec.js « utils « lib « components « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f1c9fbb00c9aa72cc5c79d3c291049bf9b818476 (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
87
88
89
90
91
import { propsUnion } from '~/vue_shared/components/lib/utils/props_utils';

describe('propsUnion', () => {
  const stringRequired = {
    type: String,
    required: true,
  };

  const stringOptional = {
    type: String,
    required: false,
  };

  const numberOptional = {
    type: Number,
    required: false,
  };

  const booleanRequired = {
    type: Boolean,
    required: true,
  };

  const FooComponent = {
    props: { foo: stringRequired },
  };

  const BarComponent = {
    props: { bar: numberOptional },
  };

  const FooBarComponent = {
    props: {
      foo: stringRequired,
      bar: numberOptional,
    },
  };

  const FooOptionalComponent = {
    props: {
      foo: stringOptional,
    },
  };

  const QuxComponent = {
    props: {
      foo: booleanRequired,
      qux: stringRequired,
    },
  };

  it('returns an empty object given no components', () => {
    expect(propsUnion([])).toEqual({});
  });

  it('merges non-overlapping props', () => {
    expect(propsUnion([FooComponent, BarComponent])).toEqual({
      ...FooComponent.props,
      ...BarComponent.props,
    });
  });

  it('merges overlapping props', () => {
    expect(propsUnion([FooComponent, BarComponent, FooBarComponent])).toEqual({
      ...FooComponent.props,
      ...BarComponent.props,
      ...FooBarComponent.props,
    });
  });

  it.each`
    components
    ${[FooComponent, FooOptionalComponent]}
    ${[FooOptionalComponent, FooComponent]}
  `('prefers required props over non-required props', ({ components }) => {
    expect(propsUnion(components)).toEqual(FooComponent.props);
  });

  it('throws if given props with conflicting types', () => {
    expect(() => propsUnion([FooComponent, QuxComponent])).toThrow(/incompatible prop types/);
  });

  it.each`
    components
    ${[{ props: ['foo', 'bar'] }]}
    ${[{ props: { foo: String, bar: Number } }]}
    ${[{ props: { foo: {}, bar: {} } }]}
  `('throw if given a non-verbose props object', ({ components }) => {
    expect(() => propsUnion(components)).toThrow(/expected verbose prop/);
  });
});