How to use loadResolver method in Jest

Best JavaScript code snippet using jest

Run Jest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

loader-test.js

Source: loader-test.js Github

copy
1import loaderFactory from '../lib';
2import { expect } from 'chai';
3
4
5const a = () => {
6}, b    = () => {
7}, c    = () => {
8}, d    = () => {
9}, e    = () => {
10}, A    = () => {
11}, B    = () => {
12};
13
14describe('loadFactory', function () {
15
16
17
18    it('should create a loader of loaders', function () {
19        const loader = loaderFactory();
20        loader.addTemplate({ A });
21        const loader2 = loaderFactory([loader]);
22
23        loader.addTemplate('Be', B)
24        expect(loader2.loadTemplate('Be')).to.eql(B);
25        expect(loader2.loadTemplate('A')).to.eql(A);
26    });
27
28    it('should load resolvers', function () {
29
30        const loader = loaderFactory([{
31            resolvers: [a, b]
32        }]);
33        const r      = loader.loadResolver(a);
34        expect(r).to.eql(b);
35
36        const loader2 = loaderFactory([loader]);
37        loader2.addLoader({ resolvers: [[c, d]] });
38
39        expect(loader2.loadResolver(a)).to.eql(b);
40        expect(loader2.loadResolver(c)).to.eql(d);
41
42        expect(loader2.loadResolver(e)).to.not.exist;
43        expect(loader.loadResolver(c)).to.not.exist;
44    });
45
46    it('should load many resolvers', function () {
47        const loader = loaderFactory([{
48            resolvers: [[a, b], [c, d], [e, null]]
49        }]);
50        expect(loader.loadResolver(a)).to.eql(b);
51        expect(loader.loadResolver(c)).to.eql(d);
52        expect(loader.loadResolver(e)).to.eql(null);
53
54    });
55    it('should load mixed', function () {
56
57        const loader = loaderFactory([{
58            resolvers: [a, b]
59        }]);
60
61        const loader2 = loaderFactory([{ resolvers: [[c, d]] }, loader]);
62
63        expect(loader2.loadResolver(a)).to.eql(b);
64        expect(loader2.loadResolver(a)).to.eql(b);
65        expect(loader2.loadResolver(c)).to.eql(d);
66
67        expect(loader2.loadResolver(e)).to.not.exist;
68        expect(loader.loadResolver(c)).to.not.exist;
69    });
70    it('should load list key val', function () {
71
72        const loader = loaderFactory();
73        loader.addResolver(a, b);
74
75        const loader2 = loaderFactory([{ resolvers: [[c, d]] }, loader]);
76        expect(loader2.listResolvers().map(v => v.name)).to.eql([c, a]);
77
78        loader2.removeResolver(a);
79        expect(loader2.listResolvers().map(v => v.name)).to.eql([c]);
80    });
81    it('should load list array val', function () {
82
83        const loader = loaderFactory();
84        loader.addResolver([a, b]);
85
86        const loader2 = loaderFactory([{ resolvers: [[c, d]] }, loader]);
87        expect(loader2.listResolvers().map(v => v.name)).to.eql([c, a]);
88
89        loader2.removeResolver(a);
90        expect(loader2.listResolvers().map(v => v.name)).to.eql([c]);
91    });
92    it('should load list nested array val', function () {
93        const loader = loaderFactory();
94        loader.addResolver([[a, b]]);
95        expect(loader.loadResolver(a)).to.eql(b);
96    });
97
98    it('should resolve object', function () {
99
100        const loader = loaderFactory([{
101            types   : {
102                A
103            },
104            template: {
105                B
106            }
107
108        }]);
109        expect(loader.loadType("A")).to.eql(A);
110        expect(loader.loadTemplate("B")).to.eql(B);
111
112    });
113    it('should resolve map', function () {
114
115        const loader = loaderFactory([{
116            types: new Map([['A', A], ['B', B]])
117        }]);
118        expect(loader.loadType("A")).to.eql(A);
119        expect(loader.loadType("B")).to.eql(B);
120
121    });
122    it('should override value', function () {
123
124        const loader = loaderFactory([{
125            types: new Map([['A', 1]])
126        }]);
127        loader.addType('A', 2);
128        loader.addLoader(loaderFactory([{
129            types: {
130                A: 3
131            }
132        }]));
133        expect(loader.loadType("A")).to.eql(3);
134    });
135    it('should map maps', function () {
136
137        const loader    = loaderFactory();
138        const propTypes = {
139            a,
140            b
141        };
142        const resolvers = {
143            a: c,
144            b: e
145        };
146        loader.addResolvers(propTypes, resolvers);
147        expect(loader.loadResolver(a)).to.eql(c);
148        expect(loader.loadResolver(b)).to.eql(e);
149        //when mapped as such the type can be resolved via string.
150        expect(loader.loadResolver('b')).to.eql(e);
151
152    });
153
154});
155
Full Screen

utils.test.js

Source: utils.test.js Github

copy
1const loadResolver = require('../src/utils/loadResolvers')
2const { isEmpty, isFunction } = require('lodash')
3const path = require('path')
4
5test('Test autoload resolvers', () => {
6  expect(
7    isFunction(loadResolver)
8  ).toBe(true)
9  
10  expect(
11    isEmpty(loadResolver(path.join(__dirname, 'utils/resolvers')))
12  ).toBe(false);
13})
14
Full Screen

schema.js

Source: schema.js Github

copy
1'use strict';
2
3
4var jsyaml  = require('../../lib/js-yaml');
5var classes = require('./classes');
6
7
8module.exports = new jsyaml.Schema({
9  include: [
10    jsyaml.DEFAULT_FULL_SCHEMA
11  ],
12  explicit: [
13    new jsyaml.Type('!tag3', {
14      loadKind: 'mapping',
15      loadResolver: classes.Tag3.fromYAMLNode,
16      dumpInstanceOf: classes.Tag3,
17      dumpRepresenter: classes.Tag3.toYAMLNode
18    }),
19    new jsyaml.Type('!tag2', {
20      loadKind: 'scalar',
21      loadResolver: classes.Tag2.fromYAMLNode,
22      dumpInstanceOf: classes.Tag2,
23      dumpRepresenter: classes.Tag2.toYAMLNode
24    }),
25    new jsyaml.Type('!tag1', {
26      loadKind: 'mapping',
27      loadResolver: classes.Tag1.fromYAMLNode,
28      dumpInstanceOf: classes.Tag1
29    }),
30    new jsyaml.Type('!foo', {
31      loadKind: 'mapping',
32      loadResolver: classes.Foo.fromYAMLNode,
33      dumpInstanceOf: classes.Foo,
34      dumpRepresenter: classes.Foo.toYAMLNode
35    })
36  ]
37});
38
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Jest on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)