Best JavaScript code snippet using stryker-parent
edit_test.ts
Source:edit_test.ts
1jest.mock("../../actions", () => ({ overwriteGroup: jest.fn() }));2import {3 editCriteria, toggleEqCriteria,4 editGtLtCriteria,5 togglePointTypeCriteria,6 toggleAndEditEqCriteria,7 clearCriteriaField,8 removeEqCriteriaValue,9 editGtLtCriteriaField,10} from "..";11import {12 fakePointGroup,13} from "../../../__test_support__/fake_state/resources";14import { cloneDeep } from "lodash";15import { DEFAULT_CRITERIA, PointGroupCriteria } from "../interfaces";16import { inputEvent } from "../../../__test_support__/fake_html_events";17import { error } from "../../../toast/toast";18import { overwriteGroup } from "../../actions";19describe("editCriteria()", () => {20 it("edits criteria: all empty", () => {21 const group = fakePointGroup();22 group.body.criteria = DEFAULT_CRITERIA;23 editCriteria(group, {})(jest.fn());24 const expectedBody = cloneDeep(group.body);25 expectedBody.criteria = DEFAULT_CRITERIA;26 expect(overwriteGroup).toHaveBeenCalledWith(group, expectedBody);27 });28 it("edits criteria: empty update", () => {29 const group = fakePointGroup();30 editCriteria(group, {})(jest.fn());31 expect(overwriteGroup).toHaveBeenCalledWith(group, group.body);32 });33 it("edits criteria: full update", () => {34 const group = fakePointGroup();35 const criteria: PointGroupCriteria = {36 day: { days_ago: 1, op: "<" },37 string_eq: { openfarm_slug: ["slug"] },38 number_eq: { x: [0] },39 number_gt: { x: 0 },40 number_lt: { x: 10 },41 };42 editCriteria(group, criteria)(jest.fn());43 const expectedBody = cloneDeep(group.body);44 expectedBody.criteria = criteria;45 expect(overwriteGroup).toHaveBeenCalledWith(group, expectedBody);46 });47});48describe("toggleEqCriteria()", () => {49 it("adds criteria", () => {50 const eqCriteria = {};51 toggleEqCriteria(eqCriteria)("openfarm_slug", "slug");52 expect(eqCriteria).toEqual({ openfarm_slug: ["slug"] });53 });54 it("removes criteria", () => {55 const eqCriteria = { openfarm_slug: ["slug"] };56 toggleEqCriteria(eqCriteria)(57 "openfarm_slug", "slug");58 expect(eqCriteria).toEqual({});59 });60 it("toggles on", () => {61 const eqCriteria = { openfarm_slug: ["slug"] };62 toggleEqCriteria(eqCriteria, "on")(63 "openfarm_slug", "slug");64 expect(eqCriteria).toEqual({ openfarm_slug: ["slug"] });65 });66 it("toggles off", () => {67 const eqCriteria = {};68 toggleEqCriteria(eqCriteria, "off")("openfarm_slug", "slug");69 expect(eqCriteria).toEqual({});70 });71});72const dispatch = jest.fn(x => x(jest.fn()));73describe("toggleAndEditEqCriteria()", () => {74 it("toggles criteria on", () => {75 const group = fakePointGroup();76 const expectedBody = cloneDeep(group.body);77 expectedBody.criteria.string_eq = { openfarm_slug: ["mint"] };78 toggleAndEditEqCriteria(group, "openfarm_slug", "mint")(dispatch);79 expect(overwriteGroup).toHaveBeenCalledWith(group, expectedBody);80 });81 it("toggles criteria on for point type", () => {82 const group = fakePointGroup();83 const expectedBody = cloneDeep(group.body);84 group.body.criteria.string_eq = {85 pointer_type: ["GenericPointer", "Plant", "ToolSlot", "Weed"],86 openfarm_slug: ["apple"],87 "meta.color": ["red"],88 };89 group.body.criteria.number_eq = {90 pullout_direction: [0]91 };92 expectedBody.criteria.string_eq = {93 pointer_type: ["GenericPointer", "Plant", "ToolSlot", "Weed"],94 openfarm_slug: ["apple", "mint"],95 };96 expectedBody.criteria.number_eq = {};97 toggleAndEditEqCriteria(group, "openfarm_slug", "mint", "Plant")(dispatch);98 expect(overwriteGroup).toHaveBeenCalledWith(group, expectedBody);99 });100 it("toggles off", () => {101 const group = fakePointGroup();102 group.body.criteria.string_eq = {103 pointer_type: ["GenericPointer", "Plant", "ToolSlot", "Weed"],104 openfarm_slug: ["mint"],105 "meta.color": ["red"],106 };107 group.body.criteria.number_eq = {108 pullout_direction: [0],109 };110 const expectedBody = cloneDeep(group.body);111 delete expectedBody.criteria.string_eq.openfarm_slug;112 toggleAndEditEqCriteria(group, "openfarm_slug", "mint", "Plant")(dispatch);113 expect(overwriteGroup).toHaveBeenCalledWith(group, expectedBody);114 });115 it("toggles on: empty criteria", () => {116 const group = fakePointGroup();117 group.body.criteria.string_eq = {118 openfarm_slug: undefined,119 "meta.color": undefined,120 };121 group.body.criteria.number_lt = { radius: 10 };122 group.body.criteria.number_gt = { radius: 1 };123 group.body.criteria.number_eq = {124 pullout_direction: undefined,125 };126 const expectedBody = cloneDeep(group.body);127 expectedBody.criteria.string_eq = {};128 expectedBody.criteria.number_lt = {};129 expectedBody.criteria.number_gt = {};130 expectedBody.criteria.number_eq = { pullout_direction: [0] };131 toggleAndEditEqCriteria(group, "pullout_direction", 0, "ToolSlot")(dispatch);132 expect(overwriteGroup).toHaveBeenCalledWith(group, expectedBody);133 });134});135describe("togglePointTypeCriteria()", () => {136 it("toggles on", () => {137 const group = fakePointGroup();138 group.body.criteria.string_eq = {139 pointer_type: ["GenericPointer"],140 openfarm_slug: ["mint"],141 "meta.color": ["red"],142 };143 const expectedBody = cloneDeep(group.body);144 expectedBody.criteria.string_eq = {145 pointer_type: ["GenericPointer", "Plant"],146 openfarm_slug: ["mint"],147 };148 togglePointTypeCriteria(group, "Plant")(dispatch);149 expect(overwriteGroup).toHaveBeenCalledWith(group, expectedBody);150 });151 it("toggles off", () => {152 const group = fakePointGroup();153 const expectedBody = cloneDeep(group.body);154 group.body.criteria.string_eq = {155 pointer_type: ["GenericPointer", "Plant"],156 openfarm_slug: ["mint"],157 "meta.color": ["red"],158 };159 expectedBody.criteria.string_eq = {160 pointer_type: ["GenericPointer"],161 openfarm_slug: ["mint"],162 };163 togglePointTypeCriteria(group, "Plant")(dispatch);164 expect(overwriteGroup).toHaveBeenCalledWith(group, expectedBody);165 });166 it("toggles on: empty criteria", () => {167 const group = fakePointGroup();168 group.body.criteria.string_eq = {};169 const expectedBody = cloneDeep(group.body);170 expectedBody.criteria.string_eq = { pointer_type: ["Plant"] };171 togglePointTypeCriteria(group, "Plant")(dispatch);172 expect(overwriteGroup).toHaveBeenCalledWith(group, expectedBody);173 });174 it("toggles off: empty criteria", () => {175 const group = fakePointGroup();176 group.body.criteria.string_eq = { pointer_type: ["ToolSlot"] };177 group.body.criteria.number_eq = {178 pullout_direction: undefined,179 };180 const expectedBody = cloneDeep(group.body);181 expectedBody.criteria.string_eq = {};182 togglePointTypeCriteria(group, "ToolSlot")(dispatch);183 expect(overwriteGroup).toHaveBeenCalledWith(group, expectedBody);184 });185 it("clears other pointer types", () => {186 const group = fakePointGroup();187 group.body.criteria.string_eq = {188 pointer_type: ["Plant", "ToolSlot"],189 "openfarm_slug": ["mint"],190 };191 const expectedBody = cloneDeep(group.body);192 expectedBody.criteria.string_eq = { pointer_type: ["Weed"] };193 togglePointTypeCriteria(group, "Weed", true)(dispatch);194 expect(overwriteGroup).toHaveBeenCalledWith(group, expectedBody);195 });196});197describe("clearCriteriaField()", () => {198 it("clears field", () => {199 const group = fakePointGroup();200 const expectedBody = cloneDeep(group.body);201 group.body.criteria.string_eq = { plant_stage: ["planted"] };202 expectedBody.criteria.string_eq = {};203 clearCriteriaField(group, ["string_eq"], ["plant_stage"])(dispatch);204 expect(overwriteGroup).toHaveBeenCalledWith(group, expectedBody);205 });206});207describe("editGtLtCriteria()", () => {208 it("adds criteria", () => {209 const group = fakePointGroup();210 const box = { x0: 0, y0: 2, x1: 3, y1: 4 };211 editGtLtCriteria(group, box)(dispatch);212 const expectedBody = cloneDeep(group.body);213 expectedBody.criteria.number_gt = { x: 0, y: 2 };214 expectedBody.criteria.number_lt = { x: 3, y: 4 };215 expect(overwriteGroup).toHaveBeenCalledWith(group, expectedBody);216 });217 it("doesn't edit criteria", () => {218 const group = fakePointGroup();219 const box = { x0: undefined, y0: 2, x1: 3, y1: 4 };220 editGtLtCriteria(group, box)(dispatch);221 expect(overwriteGroup).not.toHaveBeenCalled();222 });223});224describe("removeEqCriteriaValue()", () => {225 it("removes value", () => {226 const group = fakePointGroup();227 group.body.criteria.string_eq = { plant_stage: ["planted", "planned"] };228 removeEqCriteriaValue<string>(group, group.body.criteria.string_eq,229 "string_eq", "plant_stage", "planned")(dispatch);230 const expectedBody = cloneDeep(group.body);231 expectedBody.criteria.string_eq = { plant_stage: ["planted"] };232 expect(overwriteGroup).toHaveBeenCalledWith(group, expectedBody);233 });234});235describe("editGtLtCriteriaField()", () => {236 it("changes value", () => {237 const group = fakePointGroup();238 const e = inputEvent("1");239 editGtLtCriteriaField(group, "number_lt", "radius")(e)(dispatch);240 const expectedBody = cloneDeep(group.body);241 expectedBody.criteria.number_lt = { radius: 1 };242 expect(error).not.toHaveBeenCalled();243 expect(overwriteGroup).toHaveBeenCalledWith(group, expectedBody);244 });245 it("errors when changing value: lt", () => {246 const group = fakePointGroup();247 group.body.criteria.number_gt = { radius: 1 };248 const e = inputEvent("0");249 editGtLtCriteriaField(group, "number_lt", "radius")(e)(dispatch);250 expect(error).toHaveBeenCalledWith("Value must be greater than 1.");251 expect(overwriteGroup).not.toHaveBeenCalled();252 });253 it("errors when changing value: gt", () => {254 const group = fakePointGroup();255 group.body.criteria.number_lt = { radius: 0 };256 const e = inputEvent("1");257 editGtLtCriteriaField(group, "number_gt", "radius")(e)(dispatch);258 expect(error).toHaveBeenCalledWith("Value must be less than 0.");259 expect(overwriteGroup).not.toHaveBeenCalled();260 });261 it("doesn't error when removing value", () => {262 const group = fakePointGroup();263 group.body.criteria.number_lt = { radius: 0 };264 const e = inputEvent("");265 editGtLtCriteriaField(group, "number_gt", "radius")(e)(dispatch);266 const expectedBody = cloneDeep(group.body);267 expectedBody.criteria.number_gt = { radius: undefined };268 expect(error).not.toHaveBeenCalled();269 expect(overwriteGroup).toHaveBeenCalledWith(group, expectedBody);270 });271 it("clears incompatible criteria", () => {272 const group = fakePointGroup();273 const expectedBody = cloneDeep(group.body);274 group.body.criteria.string_eq = { plant_stage: ["planted"] };275 const e = inputEvent("1");276 editGtLtCriteriaField(277 group, "number_lt", "radius", "GenericPointer",278 )(e)(dispatch);279 expectedBody.criteria.number_lt = { radius: 1 };280 expect(error).not.toHaveBeenCalled();281 expect(overwriteGroup).toHaveBeenCalledWith(group, expectedBody);282 });...
request-pipe-specs.js
Source:request-pipe-specs.js
1module.exports = (test, dependencies) => {2 'use strict'3 const { MockRequest, Readable, Writable } = dependencies4 class TestWritable extends Writable {5 /**6 * Creates a Writable stream with support for running in a Promise7 * @param expectedBody {any} - the body to assert equality with8 * @param resolve {function} - the `resolve` function of a new Promise9 * @param reject {function} - the `reject` function of a new Promise10 */11 constructor (options) {12 super({ ...{ objectMode: true }, ...options })13 if (!options || !options.expectedBody || !options.resolve || !options.reject) {14 throw new Error('Expected expectedBody, and resolve, and reject functions to be provided')15 }16 const { resolve, reject, expectedBody } = options17 this.buffers = []18 this.response = null19 this.on('response', (res) => { this.response = res })20 this.on('error', reject)21 this.on('end', () => {22 resolve({23 expectedBody: expectedBody,24 res: this.getResponse(),25 body: this.getBody()26 })27 })28 }29 _write (chunk, encoding, next) {30 this.buffers.push(chunk)31 next()32 }33 getResponse () {34 return this.response35 }36 getBody () {37 return this.buffers.join('')38 }39 }40 return test('given MockRequest', {41 'with a string enqueued': {42 given: () => {43 const request = new MockRequest()44 const expectedBody = '{ "message": "ok" }'45 request.enqueue(null, { statusCode: 200 }, expectedBody)46 return { expectedBody, request }47 },48 'when a request is piped to a valid writable stream': {49 when: ({ request, expectedBody }) => new Promise((resolve, reject) => {50 const writable = new TestWritable({ expectedBody, resolve, reject })51 request('https://github.com/losandes/supposed').pipe(writable)52 }),53 'it should pipe the request output to the given writable stream': (then) => (err, actual) => {54 then.ifError(err)55 then.strictEqual(actual.res.statusCode, 200)56 then.strictEqual(actual.res.statusMessage, 'OK')57 then.strictEqual(actual.res.request.href, 'https://github.com/losandes/supposed')58 then.strictEqual(actual.body, actual.expectedBody)59 }60 }61 },62 'with an object enqueued': {63 given: () => {64 const request = new MockRequest()65 const expectedBody = '{"message":"ok"}'66 request.enqueue(null, { statusCode: 200 }, JSON.parse(expectedBody))67 return { expectedBody, request }68 },69 'when a request is piped to a valid writable stream': {70 when: ({ request, expectedBody }) => new Promise((resolve, reject) => {71 const writable = new TestWritable({ expectedBody, resolve, reject })72 request('https://github.com/losandes/supposed').pipe(writable)73 }),74 'it should pipe the request output to the given writable stream': (then) => (err, actual) => {75 then.ifError(err)76 then.strictEqual(actual.res.statusCode, 200)77 then.strictEqual(actual.res.statusMessage, 'OK')78 then.strictEqual(actual.res.request.href, 'https://github.com/losandes/supposed')79 then.strictEqual(actual.body, actual.expectedBody)80 }81 }82 },83 'with a stream enqueued': {84 given: () => {85 const request = new MockRequest()86 const expectedBody = '{ "message": "ok" }'87 const readable = new Readable({88 objectMode: true,89 read: function () {}90 })91 readable.push(Buffer.from(expectedBody))92 readable.push(null)93 request.enqueue(null, { statusCode: 200 }, readable)94 return { expectedBody, request }95 },96 'when a request is piped to a valid writable stream': {97 when: ({ request, expectedBody }) => new Promise((resolve, reject) => {98 const writable = new TestWritable({ expectedBody, resolve, reject })99 request('https://github.com/losandes/supposed').pipe(writable)100 }),101 'it should pipe the request output to the given writable stream': (then) => (err, actual) => {102 then.ifError(err)103 then.strictEqual(actual.res.statusCode, 200)104 then.strictEqual(actual.res.statusMessage, 'OK')105 then.strictEqual(actual.res.request.href, 'https://github.com/losandes/supposed')106 then.strictEqual(actual.body, actual.expectedBody)107 }108 }109 }110 })...
Using AI Code Generation
1const expectedBody = require('stryker-parent').expectedBody;2const expectedBody = require('stryker-parent').expectedBody;3const expectedBody = require('stryker-parent').expectedBody;4const expectedBody = require('stryker-parent').expectedBody;5const expectedBody = require('stryker-parent').expectedBody;6const expectedBody = require('stryker-parent').expectedBody;7const expectedBody = require('stryker-parent').expectedBody;8const expectedBody = require('stryker-parent').expectedBody;9const expectedBody = require('stryker-parent').expectedBody;10const expectedBody = require('stryker-parent').expectedBody;11const expectedBody = require('stryker-parent').expectedBody;12const expectedBody = require('stryker-parent').expectedBody;13const expectedBody = require('stryker-parent').expectedBody;14const expectedBody = require('stryker-parent').expectedBody;15const expectedBody = require('stryker-parent').expectedBody;16const expectedBody = require('stryker-parent').expectedBody;17const expectedBody = require('stryker-parent').expectedBody;18const expectedBody = require('stryker-parent
Using AI Code Generation
1var stryker = require('stryker-parent');2var expectedBody = stryker.expectedBody;3var expectedBody = stryker.expectedBody;4var stryker = require('stryker-parent');5var expectedBody = stryker.expectedBody;6var expectedBody = stryker.expectedBody;7var stryker = require('stryker-parent');8var expectedBody = stryker.expectedBody;9var expectedBody = stryker.expectedBody;10var stryker = require('stryker-parent');11var expectedBody = stryker.expectedBody;12var expectedBody = stryker.expectedBody;13var stryker = require('stryker-parent');14var expectedBody = stryker.expectedBody;15var expectedBody = stryker.expectedBody;16var stryker = require('stryker-parent');17var expectedBody = stryker.expectedBody;18var expectedBody = stryker.expectedBody;19var stryker = require('stryker-parent');20var expectedBody = stryker.expectedBody;21var expectedBody = stryker.expectedBody;22var stryker = require('stryker-parent');23var expectedBody = stryker.expectedBody;24var expectedBody = stryker.expectedBody;25var stryker = require('stryker-parent');26var expectedBody = stryker.expectedBody;27var expectedBody = stryker.expectedBody;28var stryker = require('stryker-parent');29var expectedBody = stryker.expectedBody;30var expectedBody = stryker.expectedBody;31var stryker = require('stryker-parent');32var expectedBody = stryker.expectedBody;33var expectedBody = stryker.expectedBody;34var stryker = require('stryker-parent');
Using AI Code Generation
1var expectedBody = require('stryker-parent').expectedBody;2var assert = require('assert');3describe('test', function () {4 it('should fail', function () {5 assert.equal(expectedBody('foo'), 'bar');6 });7});
Using AI Code Generation
1var expectedBody = require('stryker-parent-1.0.0').expectedBody;2var expectedBody = require('stryker-parent-1.0.0').expectedBody;3var expectedBody = require('stryker-parent-1.0.0').expectedBody;4var expectedBody = require('stryker-parent-1.0.0').expectedBody;5var expectedBody = require('stryker-parent-1.0.0').expectedBody;6var expectedBody = require('stryker-parent-1.0.0').expectedBody;7var expectedBody = require('stryker-parent-1.0.0').expectedBody;8var expectedBody = require('stryker-parent-1.0.0').expectedBody;9var expectedBody = require('stryker-parent-1.0.0').expectedBody;10var expectedBody = require('stryker-parent-1.0.0').expectedBody;11var expectedBody = require('stryker-parent-1.0.0').expectedBody;12var expectedBody = require('stryker-parent-1.0.0').expectedBody;
Using AI Code Generation
1var expectedBody = require('stryker-parent').expectedBody;2describe('test', function () {3 it('should work', function () {4 expect(expectedBody()).to.equal('expected body');5 });6});7module.exports.expectedBody = function () {8 return 'expected body';9};1014:26:50 (0) INFO Stryker Your mutation score is: 100.00% (0/0)1114:26:50 (0) INFO Stryker Your code was bad and you should feel bad!12I have also tried this with the files in the same directory. I have also tried this with a different file name. I have also tried this with a different test framework (Mocha). I have also tried this with a different mutation framework (Jest). I have also tried this with a different test runner (Karma). I have also tried this with a different test runner (Jest). I have also tried this with a different test runner (Mocha). I have also tried this with a different test runner (Karma). I have also tried this with a different test runner (Jest). I have also tried this with a different test runner (Mocha). I have also tried this with a different test runner (Karma). I have also tried this with a different test runner (Jest). I have also tried this with a different test runner (Mocha). I have also tried this with a different test runner (Karma). I have also tried this with a different test runner (Jest). I have also tried this with a different test runner (Mocha). I have also tried this with a different test runner (Karma). I have also tried this with a different test runner (Jest). I have also
Using AI Code Generation
1var expectedBody = require("stryker-parent").expectedBody;2var assert = require("assert");3describe("test", function () {4 it("should fail", function () {5 assert.equal(expectedBody(), "Hello World!");6 });7});8var expectedBody = require("stryker-parent").expectedBody;9var assert = require("assert");10describe("test", function () {11 it("should fail", function () {12 assert.equal(expectedBody(), "Hello World!");13 });14});15var expectedBody = require("stryker-parent").expectedBody;16var assert = require("assert");17describe("test", function () {18 it("should fail", function () {19 assert.equal(expectedBody(), "Hello World!");20 });21});22var expectedBody = require("stryker-parent").expectedBody;23var assert = require("assert");24describe("test", function () {25 it("should fail", function () {26 assert.equal(expectedBody(), "Hello World!");27 });28});29var expectedBody = require("stryker-parent").expectedBody;30var assert = require("assert");31describe("test", function () {32 it("should fail", function () {33 assert.equal(expectedBody(), "Hello World!");34 });35});36var expectedBody = require("stryker-parent").expectedBody;37var assert = require("assert");38describe("test", function () {39 it("should fail", function () {40 assert.equal(expectedBody(), "Hello World!");41 });42});43var expectedBody = require("stryker-parent").expectedBody;44var assert = require("assert");45describe("test", function () {46 it("should fail", function () {47 assert.equal(expectedBody(), "Hello World!");48 });49});50var expectedBody = require("stryker-parent").expectedBody;51var assert = require("assert");52describe("test
Using AI Code Generation
1var expectedBody = require('stryker-parent').expectedBody;2var body = {a: 1, b: 2};3assert(expectedBody(body));4var expectedBody = require('stryker-parent').expectedBody;5var body = {a: 1, b: 2};6assert(expectedBody(body));7var expectedBody = require('stryker-parent').expectedBody;8var body = {a: 1, b: 2};9assert(expectedBody(body));10var expectedBody = require('stryker-parent').expectedBody;11var body = {a: 1, b: 2};12assert(expectedBody(body));13var expectedBody = require('stryker-parent').expectedBody;14var body = {a: 1, b: 2};15assert(expectedBody(body));16var expectedBody = require('stryker-parent').expectedBody;17var body = {a: 1, b: 2};18assert(expectedBody(body));19var expectedBody = require('stryker-parent').expectedBody;20var body = {a: 1, b: 2};21assert(expectedBody(body));22var expectedBody = require('stryker-parent').expectedBody;23var body = {a: 1, b: 2};24assert(expectedBody(body));25var expectedBody = require('stryker-parent').expectedBody;26var body = {a: 1, b: 2};27assert(expectedBody(body));28var expectedBody = require('stryker-parent').expectedBody;29var body = {a: 1, b: 2};30assert(expectedBody(body));
Using AI Code Generation
1const expectedBody = require('stryker-parent').expectedBody;2describe('test', () => {3 it('should pass', () => {4 expect(expectedBody()).toBe('foo');5 });6});7module.exports = {8 expectedBody() {9 return 'foo';10 }11};12The test passes when the stryker-parent package is installed from a local package (npm pack stryker-parent) and the local package is linked (npm link stryker-parent) and the test is run with the --preserve-symlinks flag and the test is run from the stryker-parent package (npm test) and the test is run with the --preserve-symlinks-main flag and the test is run with the --preserve
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!