Skip to content
Myr

polyfills.js

This file

Path

__tests__/polyfills.js

70 lines · 1.7 KiB · JavaScript

Last changed by

test: polyfillsaleclarsonbefore adoption551d877

History of this file

Take it

test: polyfillsaleclarsonbefore adoption551d877

lines 1–70why, one step back
1const {assign} = Object
2const {ownKeys} = Reflect3const SymbolConstructor = Symbol45Symbol = undefined6Object.assign = undefined7Reflect.ownKeys = undefined89jest.resetModules()10const common = require("../src/common")1112// Reset the globals to avoid unintended effects.13Symbol = SymbolConstructor14Object.assign = assign15Reflect.ownKeys = ownKeys1617describe("Symbol", () => {18 test("NOTHING", () => {19 const value = common.NOTHING20 expect(value).toBeTruthy()21 expect(typeof value).toBe("object")22 })23 test("DRAFTABLE", () => {24 const value = common.DRAFTABLE25 expect(typeof value).toBe("string")26 })27 test("DRAFT_STATE", () => {28 const value = common.DRAFT_STATE29 expect(typeof value).toBe("string")30 })31})3233describe("Object.assign", () => {34 const {assign} = common3536 it("only copies enumerable keys", () => {37 const src = {a: 1}38 Object.defineProperty(src, "b", {value: 1})39 const dest = {}40 assign(dest, src)41 expect(dest.a).toBe(1)42 expect(dest.b).toBeUndefined()43 })4445 it("only copies own properties", () => {46 const src = Object.create({a: 1})47 src.b = 148 const dest = {}49 assign(dest, src)50 expect(dest.a).toBeUndefined()51 expect(dest.b).toBe(1)52 })53})5455describe("Reflect.ownKeys", () => {56 const {ownKeys} = common5758 // Symbol keys are always last.59 it("includes symbol keys", () => {60 const s = SymbolConstructor()61 const obj = {[s]: 1, b: 1}62 expect(ownKeys(obj)).toEqual(["b", s])63 })6465 it("includes non-enumerable keys", () => {66 const obj = {a: 1}67 Object.defineProperty(obj, "b", {value: 1})68 expect(ownKeys(obj)).toEqual(["a", "b"])69 })70})