GithubHelp home page GithubHelp logo

Comments (4)

DavidInterad avatar DavidInterad commented on May 26, 2024 1

Yes, I already updated and configured the serializer as I need it. Works great.

For anyone interested in the same:
My solution was to create a decimal serializer which keeps only the first decimal to keep the info that it is a decimal number and not an integer (e.g. 1.0 instead of 1)

    public class DecimalJsonConverter : JsonConverter<decimal>
    {
        public override decimal ReadJson(
            JsonReader reader, Type objectType, decimal existingValue, bool hasExistingValue, JsonSerializer serializer)
        {
            throw new NotImplementedException();
        }
        public override void WriteJson(JsonWriter writer, decimal value, JsonSerializer serializer)
        {
            // Customise how you want the decimal value to be output in here
            // for example, you may want to consider culture
            writer.WriteRawValue(value.ToString("0.0##############", CultureInfo.InvariantCulture));
        }
    }

and then set it before any tests using this code here (I'm using MsTest on this project):

    [TestClass]
    public static class TestInitialize
    {
        [AssemblyInitialize]
        public static void BeforeAllTests(TestContext testContext)
        {
            SnapshotSettings.GlobalSnapshotSerialiserSettings = s =>
            {
                s.Converters.Add(new CerFin.TestHelpers.DecimalJsonConverter());
            };
        }
    }

from snapper.

theramis avatar theramis commented on May 26, 2024 1

Closing as its been a while with no response and there is a suggested solution.

from snapper.

aaron-manning avatar aaron-manning commented on May 26, 2024

This is an issue for me. keep getting false negatives in CI

On one build 10.1 is 10.1, the next it's 10.10

Haven't found a solution yet other than to convert the value to a string before snapshotting

from snapper.

theramis avatar theramis commented on May 26, 2024

Hey @Dehalion and @aaron-manning ,

Just added Custom Snapshot Settings in the latest version 2.4.0. See the docs here.

You should be able to customise Newtonsoft as you like to make sure this isn't an issue.
That should hopefully solve your issue?

from snapper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.