From 5cd0d1cb7b2cd7d9e227b563807be6721f302990 Mon Sep 17 00:00:00 2001 From: dntzhang Date: Mon, 12 Nov 2018 20:53:14 +0800 Subject: [PATCH] omi - add unit testing of rpx --- packages/omi/test/index.test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/omi/test/index.test.js b/packages/omi/test/index.test.js index 1409d9b77..010e06805 100644 --- a/packages/omi/test/index.test.js +++ b/packages/omi/test/index.test.js @@ -1,6 +1,7 @@ import { getUpdatePath } from "../src/define"; import { matchGlobalData, needUpdate, fixPath } from "../src/render"; import { npn, nProps } from "../src/util"; + //proxy test //https://github.com/Palindrom/JSONPatcherProxy/blob/master/test/spec/proxySpec.js @@ -75,3 +76,21 @@ test("nProps", () => { nProps({ a: { value: 1 }, b: { value: 2 }, abC: { value: 3 } }) ).toEqual({ a: 1, b: 2, abC: 3 }); }); + +function rpx(str) { + return str.replace(/([1-9]\d*|0)(\.\d*)*rpx/g, (a, b, c) => { + return (375 * Number(b)) / 750 + 'px' + }) +} + +test("rpx", () => { + expect( + rpx('div{ width: 100rpx}') + ).toEqual('div{ width: 50px}'); +}); + +test("rpx", () => { + expect( + rpx('div{ width: 100.5rpx}') + ).toEqual('div{ width: 50px}'); +});