How to use the chance.word function in chance

To help you get started, we’ve selected a few chance examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gobwas / dm.js / test / unit / dm.js View on Github external
it("should parse config if given", function() {
            var service, definition, services,
                parameter, value, parameters,
                dm;

            (services = {})[(service = chance.word())] = (definition = {});
            (parameters = {})[(parameter = chance.word())] = (value = {});

            dm = new DM(async, loader, {
                parameters: parameters,
                services: services
            });

            expect(dm.getDefinition(service)).equal(definition);
            expect(dm.getParameter(parameter)).equal(value);
        });
    });
github gobwas / dm.js / test / unit / dm.js View on Github external
it("should return boolean", function() {
                var key;

                key = chance.word();
                dm.setDefinition(key, {
                    synthetic: true
                });

                expect(dm.has(chance.word())).to.be.false();
                expect(dm.has(key)).to.be.true();
            });
github gobwas / dm.js / test / unit / dm.js View on Github external
it("should resolve with unescaped object if it was escaped by DM#escape", function(done) {
                var escaped, target;

                escaped = DM.escape((target = { a: "@" + chance.word() }));

                dm
                    .parse(escaped)
                    .then(function(result) {
                        expect(result).equal(target);
                    })
                    .then(done, done);
            });
github gobwas / dm.js / test / unit / dm.js View on Github external
it("should return the value", function() {
                var key, value;

                dm.setParameter((key = chance.word()), (value = chance.word()));

                expect(dm.getParameter(key)).equal(value);
            });
        });
github gobwas / dm.js / test / unit / dm.js View on Github external
it("should pass parsed definition to the factory", function(done) {
                var factory, ctor, args, calls, properties,
                    parseSpy, def;

                factory = sinon.spy();
                ctor    = function() {};

                sinon.stub(loader, "require", function() {
                    return RSVP.Promise.resolve(ctor);
                });

                parseSpy = sinon.stub(dm, "parse", function(obj) {return RSVP.Promise.resolve(obj);});

                def = {
                    path:       chance.word(),
                    arguments:  (args = []),
                    calls:      (calls = []),
                    properties: (properties = {}),
                    factory:    factory
                };

                dm
                    .build(def)
                    .then(function() {
                        expect(parseSpy.callCount).equal(2);

                        expect(parseSpy.firstCall.args[0]).equal(def.path);
                        expect(parseSpy.secondCall.args[0]).deep.equal(_.omit(def, "path"));

                        expect(factory.callCount).equal(1);
                        expect(factory.firstCall.args[0].arguments).equal(args);
github gobwas / dm.js / test / unit / dm.js View on Github external
it("should return synthetic service", function(done) {
                var key, service;

                key = chance.word();
                service = {};

                dm.setDefinition(key, {
                    synthetic: true
                });

                dm
                    .parse("@" + key)
                    .then(function(result) {
                        expect(result).equal(service);
                    })
                    .then(done, done);

                dm.set(key, service);
            });
github gobwas / dm.js / test / unit / dm.js View on Github external
it("should check dm.services with given key", function() {
                var key;

                key = chance.word();
                dm.setDefinition(key, {
                    synthetic: true
                });
                dm.set(key, {});

                expect(dm.initialized(key)).to.be.true();
                expect(dm.initialized(chance.word())).to.be.false();
            });
github gobwas / dm.js / test / unit / dm.js View on Github external
it("should throw error when parameter is already set", function() {
                var key;

                key = chance.word();

                function setParameter() {
                    dm.setParameter(key, chance.word());
                }

                setParameter();

                expect(setParameter).to.throw(Error, util.format("Parameter '%s' is already exists", key));
            });
        });
github gobwas / dm.js / test / unit / dm.js View on Github external
it("should return provider for lazy services", function(done) {
                var Service;

                Service = function(){};

                sinon.stub(loader, "require", function() {
                    return async.resolve(Service);
                });

                dm.setDefinition("service", {
                    path: chance.word(),
                    lazy: true
                });

                dm
                    .get("service")
                    .then(function(provider) {
                        var firstCall;

                        expect(typeof provider).equal("function");

                        return provider();
                    })
                    .then(function(result) {
                        expect(result).to.be.instanceof(Service);
                    })
                    .then(done, done);
github gobwas / dm.js / test / unit / dm.js View on Github external
return _.reduce(new Array(chance.natural({min: 3, max: 7})), function(result, value, index) {
                        var val;

                        if (obj) {
                            result[chance.word()] = chance.word();
                        } else {
                            switch (index) {
                                case 1: {
                                    val = recursive ? makeRandomObj(false, false) : makeRandomObj(false, true);
                                    break;
                                }

                                default: {
                                    val = chance.word();
                                    break;
                                }
                            }

                            result.push(val);
                        }

                        return result;
                    }, obj ? {} : []);
                }

chance

Chance - Utility library to generate anything random

MIT
Latest version published 1 year ago

Package Health Score

76 / 100
Full package analysis