Javascript文件在DevTools源中无法正确显示

时间:2018-04-18 17:37:37

标签: javascript

我不知道为什么我在这里测试失败,有人可以解决一些问题吗?我也没有看到在DevTools源代码中显示正确的文件,所以我想这可能与它有关,但我不完全确定。

cleanObject.test.js

const cleanObject = object => {
  for (let prop in object) {
    if (
      object[prop] === null ||
      object[prop] === undefined ||
      object[prop] === ""
    ) {
      delete obj[prop];
    }
  }
};

describe("cleanObject", () => {
  it("removes null, undefined, and empty string values", () => {
    const dirty = {
      a: "",
      b: undefined,
      c: null,
      d: "value",
      e: false
    };

    const clean = cleanObject(dirty);

    expect(clean).to.deep.equal({
      d: "value",
      e: false
    });
  });
});

DevTools Sources中的cleanObject.test.js

/**
 * Take an object and remove null, empty, or undefined values.
 * 
 * @param {Object} object
 * @returns {Object}
 */
const cleanObject = (object) => {
  // complete the function
};

describe('cleanObject', () => {
  it('removes null, undefined, and empty string values', () => {
    const dirty = {
      a: '',
      b: undefined,
      c: null,
      d: 'value',
      e: false,
    };

    const clean = cleanObject(dirty);

    expect(clean).to.deep.equal({
      d: 'value',
      e: false,
    });
  });
});

似乎文件没有被发送到浏览器。谁能看到我在这里可能出错的地方?

1 个答案:

答案 0 :(得分:1)

The js file was cached (read: HTTP Caching). There are various ways to stop this from happening with server configurations, client-side cache busting, or just plain-old cache clearing.

When developing, often the best way to avoid this kind of issue is to "Empty Cache and Hard Reload" by right-clicking the refresh button with the dev-tools open: Read More