소스 검색

Fix length issue in OrderedMaps

Previously, a definiton with a 'length' property with numeric value
would result in an OrderedMap of that length.

This is now fixed and covered by tests
bubble
Leon Weidauer 7 년 전
부모
커밋
25c63b5f76
2개의 변경된 파일30개의 추가작업 그리고 3개의 파일을 삭제
  1. +1
    -1
      src/core/utils.js
  2. +29
    -2
      test/core/utils.js

+ 1
- 1
src/core/utils.js 파일 보기

@@ -41,7 +41,7 @@ export function fromJSOrdered (js) {
return !isObject(js) ? js : return !isObject(js) ? js :
Array.isArray(js) ? Array.isArray(js) ?
Im.Seq(js).map(fromJSOrdered).toList() : Im.Seq(js).map(fromJSOrdered).toList() :
Im.Seq(js).map(fromJSOrdered).toOrderedMap()
Im.OrderedMap(js).map(fromJSOrdered)
} }


export function bindToState(obj, state) { export function bindToState(obj, state) {


+ 29
- 2
test/core/utils.js 파일 보기

@@ -1,10 +1,10 @@
/* eslint-env mocha */ /* eslint-env mocha */
import expect from "expect" import expect from "expect"
import { fromJS } from "immutable" import { fromJS } from "immutable"
import { mapToList, validateNumber, validateInteger, validateParam, validateFile } from "core/utils"
import { mapToList, validateNumber, validateInteger, validateParam, validateFile, fromJSOrdered } from "core/utils"
import win from "core/window" import win from "core/window"


describe("utils", function(){
describe("utils", function() {


describe("mapToList", function(){ describe("mapToList", function(){


@@ -306,4 +306,31 @@ describe("utils", function(){
expect( result ).toEqual( [{index: 0, error: "Value must be an integer"}, {index: 1, error: "Value must be an integer"}] ) expect( result ).toEqual( [{index: 0, error: "Value must be an integer"}, {index: 1, error: "Value must be an integer"}] )
}) })
}) })

describe("fromJSOrdered", () => {
it("should create an OrderedMap from an object", () => {
const param = {
value: "test"
}

const result = fromJSOrdered(param).toJS()
expect( result ).toEqual( { value: "test" } )
})

it("should not use an object's length property for Map size", () => {
const param = {
length: 5
}

const result = fromJSOrdered(param).toJS()
expect( result ).toEqual( { length: 5 } )
})

it("should create an OrderedMap from an array", () => {
const param = [1, 1, 2, 3, 5, 8]

const result = fromJSOrdered(param).toJS()
expect( result ).toEqual( [1, 1, 2, 3, 5, 8] )
})
})
}) })

불러오는 중...
취소
저장